Qt window types, window flags and window properties

1. Window type

The Qt Window Flags enumeration type is used to specify various window system properties for widgets. Some of these flags depend on whether the underlying window manager supports them. The following is a list of window types:

window type

describe

Qt::QWidget

This is the default type of QWidget. Widgets of this type are child widgets if they have a parent, or standalone windows if they have no parent.

Qt::Window

Typically has a window system frame and a title bar. Note that this flag cannot be unset if the widget has no parent control (can be used in cases where the popup child window is much larger than the parent window).

Qt::Dialog

Dialogs (usually without maximize or minimize buttons in the title bar). dget This is the default type of QDialog. If you want to use it as a modal dialog, you should start it from another window.

Qt::Sheet

macOS form-style windows. Since using a sheet implies window modality, the recommended way is to use QWidget::setWindowModality() or QDialog::open().

Qt::Drawer

macOS drawer windows.

Qt::Popup

A popup toplevel window, i.e. it is modal but has a window system frame that fits into the popup menu.

Qt::Tool

tool window. A tool window is usually a small window with a smaller-than-usual title bar and decorations, usually for a collection of tool buttons. If there is a parent widget, the tool window will always stay on it.

Qt::Tooltip

Tooltip window. This is used internally to implement tooltips without title bars and window borders.

Qt::SplashScreen

splash screen. This is the default type for QSplashScreen.

Qt::SubWindow

Subwindows, such as the QMdiSubWindow widget.

Qt::ForeignWindow

Represents a handle to a native platform window created by another process or manually using native code.

Qt::CoverWindow

Represents a cover window, for example, displayed when the application is minimized on the BlackBerry platform.

2. Window sign

The following is a comparison table for multiple window flags that can be set:

window sign

describe

Qt::MSWindowsFixedSizeDialogHint

Windows system fixed size narrow border window

Qt::X11BypassWindowManagerHint

A window without window borders completely ignores the window manager and the user cannot use the keyboard for input (unless the QWidget::activateWindow() function is called manually

Qt::FramelessWindowHint

Unable to move and resize windows without window borders

Qt::NoDropShadowWindowHint

Disable window shadows

Qt::WindowTitleHint

window with title bar

Qt::WindowSystemMenuHint

Window with system menu and possibly a close button

Qt::CustomizeWindowHint

Turn off the default window title tooltip

Qt::WindowMinimizeButtonHint

Add a minimize button to the window

Qt::WindowMaximizeButtonHint

Add a maximize button to the window

Qt::WindowCloseButtonHint

Add a close button to the window

Qt::WindowContextHelpButtonHint

Add a help button to the window

Qt::WindowShadeButtonHint

Adds a shadow button in place of the minimize button if the window manager supports it

Qt::WindowStaysOnTopHint

Notification window system sticky window

Qt::WindowStaysOnBottomHint

The notification window system is placed on the bottom window

  • Common examples:
  • // Set no window border | window top this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
  • Qt has a Demo called Window Flags that shows how to use the available window flag types in Qt to specify window system properties . In the QtCreator software you can find:

The benefits of this article, free to receive Qt development learning materials package, technical video, including (C++ language foundation, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project combat, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓↓↓↓See below↓↓Click on the bottom of the article to receive the fee↓↓ 

3. Window Properties

The Qt::WidgetAttribute enumeration attribute can be set on the QWidget object through the setAttribute function, thereby changing some characteristics of the QWidget object.

  • Qt::WA_AcceptDrops: Accepts drag and drop, QWidget::setAcceptDrops() is a convenience function for this setting.
  • Qt::WA_DeleteOnClose: QWidget is deleted when it is closed.
  • Qt::WA_Disabled: Set the widget (note that it is a widget, not valid for the window) to be disabled (relative to calling setEnabled(false);).
  • Qt::WA_ForceUpdatesDisabled: Disables updates, it will remain disabled even if all its ancestors are set to enable updates. (Equivalent to calling QWidget::setUpdatesEnabled()).
  • Qt::WA_Hover: Forces Qt to generate paint events when the mouse enters or leaves the widget. This feature is typically used when implementing custom styles.
  • Qt::WA_InputMethodEnabled: Enables input methods for Asian languages. Must be set when creating a custom text edit widget.
  • Qt::WA_KeyboardFocusChange: Change the focus when the user uses the keyboard (tab, backtab or shortcut). Used for top-level window settings.
  • Qt::WA_NoChildEventsForParent: The widget does not wish to send ChildAdded or ChildRemoved events to its parent.
  • Qt::WA_NoChildEventsFromChildren: The widget does not wish to receive ChildAdded or ChildRemoved events sent from its children.
  • Qt::WA_NoMousePropagation: Disables the propagation of mouse events to the widget's parent. This property is disabled by default.
  • Qt::WA_TransparentForMouseEvents: Will disable the delivery of mouse events to the widget and its children. This property is disabled by default.
  • Qt::WA_NoSystemBackground: The widget has no background, that is, the background will not be automatically repainted when the widget receives a paint event. The effect of setting the window is completely black.
  • Qt::WA_OpaquePaintEvent: The widget paints all of its pixels when it receives a paint event. Therefore, operations such as updates, resizing, scrolling, and focus changes do not need to erase the widget before generating paint events.
  • Qt::WA_PaintUnclipped: Make the drawing of all QPainter objects operated on this widget not clipped (that is, the clipping area set by QPainter is invalid). This flag is only supported by widgets with the Qt::WA_PaintOnScreen flag set.
  • Qt::WA_PaintOnScreen: Indicates that the widget is to be drawn directly on the screen. Widgets with this attribute set do not participate in composition management, i.e. they cannot be translucent or glow through translucent overlapping widgets. It will disable double buffering.
  • Qt::WA_QuitOnClose: Causes Qt to quit the application when the widget received closeEvent() as the last one. This behavior can be modified using the QApplication::quitOnLastWindowClosed property. By default, this property is set for all widgets of type Qt::Window.
  • Qt::WA_Resized: Indicates that the widget has an explicit size. This flag is set or cleared by QWidget::resize() and QWidget::setGeometry().
  • Qt::WA_AlwaysShowToolTips: Set the window (note that it is a window, which is invalid when QWidget is used as a child component) to display prompt information when it is inactive. (setToolTip() sets the window prompt information)

The following highlights a few commonly used or special attributes:

3.1 Qt::WA_TransparentForMouseEvents

The explanation of Qt::WA_TransparentForMouseEvents in the Qt Assistant is as follows:

When enabled, this attribute disables the delivery of mouse events to the widget and its children. Mouse events are delivered to other widgets as if the widget and its children were not present in the widget hierarchy; mouse clicks and other events effectively "pass through" them. This attribute is disabled by default.

The effect is:

When this property is enabled, all mouse events sent to the form and child controls inside the form will be invalidated. Mouse events are distributed to other widgets as if this widget and its child controls did not appear in the widget hierarchy. Mouse clicks and other mouse events efficiently pass through (that is, bypass) this widget and its sub-controls. This property is disabled and not enabled by default.

3.2 Qt::WA_StaticContents

Qt officially explains Qt::WA_StaticContents as follows:

Indicates that the widget contents are north-west aligned and static. On resize, such a widget will receive paint events only for parts of itself that are newly visible. This flag is set or cleared by the widget's author.

Translated into Chinese means: Indicates that the content of the form is aligned to the northwest direction, that is, the upper left corner, and is static. When the form is resized, only those newly visible parts of the form are drawn. This flag is cleared or set by the developer of the form.

Normally, when resizing a widget, Qt generates a paint event for the entire visible area of ​​the widget. But if the widget is created with the Qt::WA_StaticContens attribute, then the area of ​​the drawing event will be strictly limited to the part that has not been displayed before. This means that if the widget is resized to be smaller than it was before, no paint events will be generated at all. In some cases, this can improve performance and reduce cpu efficiency. When drawing things before is time-consuming (such as: a certain curve, a certain figure is obtained through a certain complex mathematical operation), it is not important to Drawing without recalculation will save a lot of cpu time and greatly improve efficiency.

3.3 Qt::WA_OpaquePaintEvent

Qt::WA_OpaquePaintEvent is explained in the Qt Assistant as follows:

Indicates that the widget paints all its pixels when it receives a paint event. Thus, it is not required for operations like updating, resizing, scrolling and focus changes to erase the widget before generating paint events. The use of WA_OpaquePaintEvent provides a small optimization by helping to reduce flicker on systems that do not support double buffering and avoiding computational cycles necessary to erase the background prior to painting. Note: Unlike WA_NoSystemBackground, WA_OpaquePaintEvent makes an effort to avoid transparent window backgrounds. This flag is set or cleared by the widget's author.

Its meaning is roughly that:

Instructs the form to paint all of its pixels when it receives a paint event. Therefore, the form is not required to erase the form background for updates, resizing, scroll bar scrolling, focus changes, etc., before receiving paint events. Using this flag provides a small optimization for systems that don't support double buffers, reducing flickering; while avoiding the time-consuming calculations required to erase the background before drawing. Unlike the WA_NoSystemBackground flag, WA_OpaquePaintEvent tries to prevent the background of the form from being transparent. This flag is set or cleared by the developer of the form.

Note: Sometimes setting the WA_OpaquePaintEvent attribute will affect the background color of the window set by the style sheet.

The above is the official explanation of Qt. My personal understanding is as follows:

  • Instructs the form to paint all of its pixels when it receives a paint event. The personal understanding of "receiving a drawing event" here should be that when the drawing event is received for the first time, that is, when the form is constructed, all the pixels of the form are drawn once.
  • Once the form is completed, after drawing all the pixels as mentioned above, all subsequent updates, size changes, focus changes, scroll bar scrolling and other operations related to the form will not erase the form background. That is to say, the things drawn before will not be erased and redrawn. That is, the previous drawing is not recalculated or redrawn. When drawing things before is time-consuming (such as: a certain curve, a certain figure is obtained through a certain complex mathematical operation), do not redraw or recalculate, which will save a lot of cpu time and greatly improve efficiency ( This is why it does not blink after setting this flag).

3.4 Qt::WA_NoMousePropagation

In Qt, mouse events include: mouse button press, mouse button release, mouse double-click event, mouse move event. They are respectively handled by the following event handlers (event handlers, which are actually functions that can be overriden):

virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void mouseDoubleClickEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);

The mouse event is a bubbling event, and the mouse event will always be routed along its parent chain until the widget where its ancestor is located accepts it, or an event filter consumes it.

Note: If a mouse event is routed to a widget that contains the Qt::WA_NoMousePropagation window property (i.e. the property is set to true), the mouse event is not routed further down the parent control chain.

The benefits of this article, free to receive Qt development learning materials package, technical video, including (C++ language foundation, introduction to Qt programming, QT signal and slot mechanism, QT interface development-image drawing, QT network, QT database programming, QT project combat, QSS, OpenCV, Quick module, interview questions, etc.) ↓↓↓↓↓↓See below↓↓Click on the bottom of the article to receive the fee↓↓

Guess you like

Origin blog.csdn.net/QtCompany/article/details/131647535