Qt: 窗口 flag, modal, state 属性设置
Qt::WindowFlags
参考:Qt Help
Window flags are a combination of a type (e.g. Qt::Dialog) and zero or more hints to the window system (e.g. Qt::FramelessWindowHint
).
A window flag is either a type or a hint.
A type is used to specify various window-system properties for the widget.
A widget can only have one type, and the default is Qt::Widget. However, a widget can have zero or more hints. The hints are used to customize the appearance of top-level windows.
(1)常用几个主要 type:
(2)自定义Top窗口外观 hints
- Qt::FramelessWindowHint: Produces a borderless window. The user cannot move or resize a borderless window via the window system.
- Qt::X11BypassWindowManagerHint: Bypass the window manager completely. This results in a borderless window that is not managed at all (i.e., no keyboard input unless you call
QWidget::activateWindow()
manually).
(3) 自定义窗口控制
- Qt::WindowStaysOnTopHint: Informs the window system that the window should stay on top of all other windows. Note that on some window managers on X11 you also have to pass Qt::X11BypassWindowManagerHint for this flag to work correctly.
- Qt::WindowDoesNotAcceptFocus: Informs the window system that this window should not receive the input focus.
用函数 void setWindowFlags(Qt::WindowFlags type)
来设置窗口 flag
setWindowFlag(Qt::Dialog | Qt::FramelessWindowHint)
QWidget::windowModality
参考:Qt Help
This property holds which windows are blocked by the modal widget.
This property only makes sense for windows.
A modal widget prevents widgets in other windows from getting input. The value of this property controls which windows are blocked when the widget is visible. Changing this property while the window is visible has no effect; you must hide() the widget first, then show() it again.
By default, this property is Qt::NonModal.
enum Qt::WindowModality
函数 void setWindowModality(Qt::WindowModality windowModality)
来设置该属性。
Qt::WindowState
参考:Qt Help
This enum type is used to specify the current state of a top-level window.
enum Qt::WindowState
flags Qt::WindowStates
The WindowStates type is a typedef for QFlag. It stores an OR combination of WindowState values.
void QWidget::activateWindow()
参考:Qt Help
Sets the top-level widget containing this widget to be the active window.
top-level widget: A widget without a parent widget is always an independent window (top-level widget).
An active window is a visible top-level window that has the keyboard input focus.
This function performs the same operation as clicking the mouse on the title bar of a top-level window.
On X11, the result depends on the Window Manager. If you want to ensure that the window is stacked on top as well you should also call raise(). Note that the window must be visible, otherwise activateWindow() has no effect.
isActiveWindow : const bool
This property holds whether this widget’s window is the active window
The active window is the window that contains the widget that has keyboard focus (The window may still have focus if it has no widgets or none of its widgets accepts keyboard focus).
When popup windows are visible, this property is true for both the active window and for the popup.
By default, this property is false.
void QWidget::raise()
Raises this widget to the top of the parent widget’s stack.
After this call the widget will be visually in front of any overlapping sibling widgets.
void QWidget::lower()
Lowers the widget to the bottom of the parent widget’s stack.
After this call the widget will be visually behind (and therefore obscured by) any overlapping sibling widgets.