NodeWidget

Abstract class to add functionalities common to all Widgets.

This class implements all methods, properties of Qt's QWidget class so that it can be inherited by all widgets

NodeWidget is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all widget's easily. Additionally it helps in type checking process. If you wish to create a div like widget use QWidget instead.

NodeWidget is the base class for all widgets. It inherits from another abstract class EventWidget

Example

const {
NodeWidget,
QPushButton,
QWidget,
QRadioButton
} = require("@nodegui/nodegui");
// showWidget can accept any widget since it expects NodeWidget
const showWidget = (widget: NodeWidget) => {
widget.show();
};
showWidget(new QPushButton());
showWidget(new QWidget());
showWidget(new QRadioButton());

NodeWidget will list all methods and properties that are common to all widgets in the NodeGui world.

Static Methods

NodeWidget can access all the static methods defined in EventWidget

Instance Properties

NodeWidget can access all the instance properties defined in EventWidget

Additionally it also has the following instance properties:

widget.layout

A NodeLayout representing current layout that is set on the widget.

widget.type

This will return the string widget for all widgets.

Instance Methods

NodeWidget can access all the instance methods defined in EventWidget

Additionally it also has the following instance methods:

widget.show()

Shows the widget and its children. It calls the native method QWidget: show.

widget.resize(width, height)

Resizes the widget. It calls the native method QWidget: resize.

  • width number - Pixels.
  • height number - Pixels.

widget.close()

Closes this widget. It calls the native method QWidget: close. Returns true if the widget was closed; otherwise returns false.

widget.setLayout(layout)

Sets the layout manager for this widget to layout. It calls the native method QWidget: setLayout.

  • layout NodeLayout - Any layout that inherits from NodeLayout class.

widget.setStyleSheet(styleSheet)

Sets the property that holds the widget's style sheet. It calls the native method QWidget: styleSheet.

  • styleSheet string - String which holds the widget's style sheet. Make sure you create this string using StyleSheet.create()

widget.setCursor(cursor)

Sets the window mouse cursor. It calls the native method QWidget: setCursor.

widget.setWindowIcon(icon)

Sets the window icon. It calls the native method QWidget: setWindowIcon.

  • icon QIcon - Specifies icon for the window.

widget.setWindowState(state)

Sets the window state. It calls the native method QWidget: setWindowState.

widget.setWindowTitle(title)

Sets the window title property. It calls the native method QWidget: setWindowTitle.

  • title string - String which holds the windows title.

widget.styleSheet()

Gets the property that holds the widget's style sheet. It calls the native method QWidget: styleSheet.

widget.hide()

Hides the widget and its children. It calls the native method QWidget: hide.

widget.move(x, y)

Sets the screen position of the widget. It calls the native method QWidget: move.

  • x number - Pixels.
  • y number - Pixels.

widget.setObjectName(objectName)

Sets the object name of the widget in Qt. It calls the native method QObject: setObjectName. Object name can be analogous to id of an element in the web world. Using the objectName of the widget one can reference it in the Qt's stylesheet much like what we do with id in the web world.

  • objectName string - String which holds the widget's object name.

widget.objectName()

Gets the property that holds the widget's object name. It calls the native method QObject: setObjectName.

widget.setMouseTracking(isMouseTracked)

Sets the property that tells whether mouseTracking is enabled for the widget. It calls the native method QWidget: mouseTracking.

  • isMouseTracked boolean - Set it to true to enable mouse tracking.

widget.setEnabled(enabled)

Sets the property that tells whether the widget is enabled. It calls the native method QWidget: enabled. In general an enabled widget handles keyboard and mouse events; a disabled widget does not.

  • enabled boolean - Set it to true to enable the widget.

widget.setFixedSize(width, height)

Sets both the minimum and maximum sizes of the widget. It calls the native method QWidget: setFixedSize.

  • width number - Pixels.
  • height number - Pixels.

widget.setGeometry(x, y, width, height)

Sets the screen position as well as size of the widget. It calls the native method QWidget: setGeometry.

  • x number - Pixels.
  • y number - Pixels.
  • width number - Pixels.
  • height number - Pixels.

widget.setMaximumSize(width, height)

Sets the maximum size of the widget. It calls the native method QWidget: setMaximumSize.

  • width number - Pixels.
  • height number - Pixels.

widget.setMinimumSize(width, height)

Sets the minimum size of the widget. It calls the native method QWidget: setMinimumSize.

  • width number - Pixels.
  • height number - Pixels.

widget.repaint()

Repaints the widget. It calls the native method QWidget: repaint.

widget.update()

Updates the widget. It calls the native method QWidget: update.

widget.pos()

Returns the current widget position. It calls the native method QWidget: pos. The returned size object contains x and y coordinates in pixels.

widget.size()

Returns the current widget size. It calls the native method QWidget: size. The returned size object contains width and height in pixels.

widget.updateGeometry()

Notifies the layout system that this widget has changed and may need to change geometry.

widget.setAttribute(attributeName, switchOn)

Sets the attribute attribute on this widget if on is true; otherwise clears the attribute. It calls the native method QWidget: setAttribute.

  • attributeName WidgetAttribute - Enum from WidgetAttribute.
  • switchOn boolean - set it to true if you want to enable an attribute.

widget.testAttribute(attributeName)

Returns true if attribute attribute is set on this widget; otherwise returns false. It calls the native method QWidget: testAttribute.

  • attributeName WidgetAttribute - Enum from WidgetAttribute.

widget.inherits(className)

Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. A class is considered to inherit itself. Example:

const progressBar = new QProgressBar();
progressBar.inherits("QObject"); // returns true
progressBar.inherits("QProgressBar"); // returns true
progressBar.inherits("QTabWidget"); // returns false
  • className string - Name of the class to get if this widget inherits from.