当前位置:网站首页>Qt/pyqt window type and window flag
Qt/pyqt window type and window flag
2022-07-29 08:05:00 【muzing_】
brief introduction
Qt There are many types and flags for windows , Special windows for custom development ( Such as borderless window, etc ). Whether these types and signs can be realized 、 What's the effect , It depends on whether the window system of the operating system supports and effects . In most cases , Use the default window type .
Each window can only have one window type , But there can be more than one window logo decoration .

Enumerate the list of values
Translated from Official documents
This enumeration value is used to specify various window systems for the control (window-system) attribute . They are generally rare , But in a few cases it is necessary . Some of these flags depend on whether the underlying window manager supports .
Window type
The main types include :
| Constant | value | describe |
|---|---|---|
| Qt.Widget | 0x00000000 | QWidget Default type of . If this type of control has a parent control, it will be used as a child control , If there is no parent control, it is an independent window . See Qt.Window and Qt.SubWindow. |
| Qt.Window | 0x00000001 | Indicates that the control is a window , Whether the control has a parent control or not , It usually has a window system frame and a title bar . Note that if the control has no parent , You cannot unset this flag . |
| Qt.Dialog | 0x00000002 | Window | Indicates that the control is a window that should be decorated as a dialog ( namely , Generally, there is no maximize or minimize button in the title bar ). This is a QDialog Default type of . If you want to use it as a modal dialog , It should start from another window , Or have a parent window and QWidget.windowModality Properties together . If it is set to mode , The dialog box will prevent other top-level windows in the application from getting any input . We call a top-level window with a parent control a secondary window (secondary window). |
| Qt.Sheet | 0x00000004 | Window | Indicates that the window is macOS Upper sheet. Due to the use sheet Means window mode , Therefore, the recommended method is to use QWidget.setWindowModality() or QDialog::open() replace . |
| Qt.Popup | 0x00000008 | Window | Indicates that the control is a pop-up top-level window , That is, it is modal , But it has a window system framework suitable for pop-up menus . |
| Qt.Tool | Popup | Dialog | Indicates that the control is a tool window . The tool window is usually a small window , It has a smaller title bar and decoration than ordinary windows , Generally used for the collection of tool buttons . If there is a parent control , The tool window will always remain at its top . If there is no parent , You can also consider using it Qt::WindowStaysOnTopHint. If the window system supports , Tool windows can be decorated with lighter frames . It can also be associated with Qt::FramelessWindowHint Use a combination of . stay macOS On , The tool window corresponds to the NSPanel class . This means that the window is above the normal window , Therefore, ordinary windows cannot be placed on top of them . By default , When the application is inactive , The tool window will disappear . This can be done by Qt.WA_MacAlwaysShowToolWindow Attribute to control . |
| Qt.ToolTip | Popup | Sheet | Indicates that the control is a tooltip . This is used internally to implement tooltips . |
| Qt.SplashScreen | ToolTip | Dialog | Indicates that the window is a flashing screen (splash screen). This is a QSplashScreen Default type of . |
| Qt.SubWindow | 0x00000012 | Indicates that this control is a child window , for example QMdiSubWindow Control . |
| Qt.ForeignWindow | 0x00000020 | Window | Indicates that this window object is a handle , Represents a local platform window created by another process or manually using local code . |
| Qt.CoverWindow | 0x00000040 | Window | Indicates that the window represents an overlay window , Show when minimizing applications on some platforms . |
Window sign
There are also many flags that can be used to customize the appearance of top-level windows . This has no effect on other windows :
| Constant | value | describe |
|---|---|---|
| Qt.MSWindowsFixedSizeDialogHint | 0x00000100 | At Microsoft Windows Provide a thin dialog box border for the window . This style is traditionally used for fixed size dialogs . Be careful : It is not recommended to use this flag in a multi display environment , Because the system will force the window to maintain its original size when moving across the screen , This is particularly unpopular when using displays with different resolutions . |
| Qt.MSWindowsOwnDC | 0x00000200 | At Microsoft Windows Provides its own display context for the window . |
| Qt.BypassWindowManagerHint | 0x00000400 | This flag can be used to indicate to the platform plug-in that it should be disabled “ all ” Window Manager Protocol . According to the operating system of the application and the operation of the window manager , The behavior of the logo will be different . This flag can be used to get the local window without setting the configuration . |
| Qt.X11BypassWindowManagerHint | BypassWindowManagerHint | Bypass the window manager completely . This leads to a completely unmanaged borderless window ( namely , Unless called by hand QWidget.activateWindow(), Otherwise, there is no keyboard input ). |
| Qt.FramelessWindowHint | 0x00000800 | Generate a borderless window . Users cannot move or resize borderless windows through the window system . stay X11 On , The result of the flag depends on the window manager and its understanding Motif and / or NETWM The ability of . Most existing modern window managers can handle this problem . |
| Qt.NoDropShadowWindowHint | 0x40000000 | Disable window projection on supported platforms . |
| Qt.CustomizeWindowHint | 0x02000000 | Turn off the default window title hints. |
| Qt.WindowTitleHint | 0x00001000 | Add a title bar to the window . |
| Qt.WindowSystemMenuHint | 0x00002000 | Add a system menu to the window , It's probably a close button . If you want to hide / Show close button , A better way is to use WindowCloseButtonHint. |
| Qt.WindowMinimizeButtonHint | 0x00004000 | Add a minimize button to the window . On some platforms , It means WindowSystemMenuHint It's also in effect . |
| Qt.WindowMaximizeButtonHint | 0x00008000 | Add the maximize button to the window . On some platforms , It means WindowSystemMenuHint It's also in effect . |
| Qt.WindowMinMaxButtonsHint | WindowMinimizeButtonHint | WindowMaximizeButtonHint | Add maximization to the window 、 Minimize button . On some platforms , It means WindowSystemMenuHint It's also in effect . |
| Qt.WindowCloseButtonHint | 0x08000000 | Add a close button to the window . On some platforms , It means WindowSystemMenuHint It's also in effect . |
| Qt.WindowContextHelpButtonHint | 0x00010000 | Add a context help button to the dialog . On some platforms , It means WindowSystemMenuHint It's also in effect . |
| Qt.MacWindowToolBarButtonHint | 0x10000000 | stay macOS Add a toolbar button on ( namely , The oval button at the top right of the window with toolbar ) |
| Qt.WindowFullscreenButtonHint | 0x80000000 | stay macOS Add a full screen button on |
| Qt.BypassGraphicsProxyWidget | 0x20000000 | If the parent control is already embedded , Then prevent the window and its child windows from automatically embedding themselves into QGraphicsProxyWidget in . If you want the control to always be the top-level control on the desktop , You can set this flag , Whether or not the parent control is embedded in the scene . |
| Qt.WindowShadeButtonHint | 0x00020000 | If the underlying window manager supports , Add a shadow button instead of the minimize button . |
| Qt.WindowStaysOnTopHint | 0x00040000 | Notify the window system that this window should be above all other windows . Be careful , In some cases based on X11 Window manager , Must also pass Qt.X11BypassWindowManagerHint To make this sign work properly . |
| Qt.WindowStaysOnBottomHint | 0x04000000 | The notification window system should be located under all other windows . |
| Qt.WindowTransparentForInput | 0x00080000 | Notification window system this window is only used for output ( Show something ) Instead of accepting input . Therefore, the input event should be skipped as if it did not exist . |
| Qt.WindowOverridesSystemGestures | 0x00100000 | The notification window system realizes its own set of gestures , System level gestures ( For example, three finger switch screen ) Should be disabled . |
| Qt.WindowDoesNotAcceptFocus | 0x00200000 | The notification window system does not accept input focus . |
| Qt.MaximizeUsingFullscreenGeometryHint | 0x00400000 | The notification window system should use as much screen geometry as possible when maximizing windows , Including possible UI The area covered ( Such as status bar or application launcher ). This may cause windows to be placed on these systems UI under , The specific situation depends on whether the platform supports . When this flag is enabled , The user is responsible for QScreen.availableGeometry() Also take into account , So that any in the application that requires user interaction UI Elements will not be used by the system UI Cover . |
| Qt.WindowType_Mask | 0x000000ff | Mask used to extract the window type from the window flag . |
Code instance
Qt The official offers a display of various window types 、 Example of the actual effect of window logo Window Flags Example, Here, the original C++ Code “ translate ” to PySide6 edition .
# window_flags_example.py
# @muzing <[email protected]>
import sys
from PySide6 import QtWidgets
from PySide6.QtCore import Qt, QCoreApplication
""" This case is Qt Official case Window Flags Example Of PySide6 Porting version https://doc.qt.io/qt-6/qtwidgets-widgets-windowflags-example.html Used to show in different Window Flags Under the mark , The style state of the top-level window https://doc.qt.io/qt-6/qt.html#WindowType-enum """
class ControllerWindow(QtWidgets.QWidget):
""" Control window class """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.preview_window = PreviewWindow(self) # Create a preview window
self.create_type_groupbox()
self.create_hints_groupbox()
quit_button = QtWidgets.QPushButton("Quit")
quit_button.clicked.connect(QCoreApplication.quit) # type: ignore
bottom_layout = QtWidgets.QHBoxLayout()
bottom_layout.addStretch()
bottom_layout.addWidget(quit_button)
main_layout = QtWidgets.QVBoxLayout()
main_layout.addWidget(self.type_groupbox)
main_layout.addWidget(self.hints_group_box)
main_layout.addLayout(bottom_layout)
self.setLayout(main_layout)
self.setWindowTitle("Window Flags")
self.update_preview()
def create_type_groupbox(self) -> None:
""" establish type Radio button , And layout it in the group box \n :return: None """
self.type_groupbox = QtWidgets.QGroupBox("Type")
self.window_radiobutton = self.crate_radiobutton("Window")
self.dialog_radiobutton = self.crate_radiobutton("Dialog")
self.sheet_radiobutton = self.crate_radiobutton("Sheet")
self.popup_radiobutton = self.crate_radiobutton("Popup")
self.tool_radiobutton = self.crate_radiobutton("Tool")
self.tool_tip_radiobutton = self.crate_radiobutton("Tooltip")
self.splash_screen_radiobutton = self.crate_radiobutton("Splash screen")
self.sub_window_radiobutton = self.crate_radiobutton("Sub window")
self.foreign_window_radiobutton = self.crate_radiobutton("Foreign window")
self.cover_window_radiobutton = self.crate_radiobutton("Cover window")
self.window_radiobutton.setChecked(True)
layout = QtWidgets.QGridLayout()
layout.addWidget(self.window_radiobutton, 0, 0)
layout.addWidget(self.dialog_radiobutton, 1, 0)
layout.addWidget(self.sheet_radiobutton, 2, 0)
layout.addWidget(self.popup_radiobutton, 3, 0)
layout.addWidget(self.tool_radiobutton, 4, 0)
layout.addWidget(self.tool_tip_radiobutton, 0, 1)
layout.addWidget(self.splash_screen_radiobutton, 1, 1)
layout.addWidget(self.sub_window_radiobutton, 2, 1)
layout.addWidget(self.foreign_window_radiobutton, 3, 1)
layout.addWidget(self.cover_window_radiobutton, 4, 1)
self.type_groupbox.setLayout(layout)
def create_hints_groupbox(self) -> None:
""" establish hints Check box , And layout it in the group box \n :return: None """
self.hints_group_box = QtWidgets.QGroupBox("Hints")
self.ms_windows_fixed_size_dialog_checkbox = self.create_checkbox(
"MS Windows fixed size dialog"
)
self.bypass_window_manager_checkbox = self.create_checkbox("Bypass window manager")
self.x11_bypass_window_manager_checkbox = self.create_checkbox("X11 bypass window manager")
self.frameless_window_check_box = self.create_checkbox("Frameless window")
self.window_no_shadow_check_box = self.create_checkbox("No drop shadow")
self.window_title_check_box = self.create_checkbox("Window title")
self.window_system_menu_check_box = self.create_checkbox("Window system menu")
self.window_minimize_button_check_box = self.create_checkbox("Window minimize button")
self.window_maximize_button_check_box = self.create_checkbox("Window maximize button")
self.window_close_button_check_box = self.create_checkbox("Window close button")
self.window_context_help_button_check_box = self.create_checkbox(
"Window context help button"
)
self.window_shade_button_check_box = self.create_checkbox("Window shade button")
self.window_stays_on_top_check_box = self.create_checkbox("Window stays on top")
self.window_stays_on_bottom_check_box = self.create_checkbox("Window stays on bottom")
self.customize_window_hint_check_box = self.create_checkbox("Customize window")
self.window_transparent_for_input_check_box = self.create_checkbox(
"Window transparent for input"
)
self.ms_windows_own_dc_check_box = self.create_checkbox("MS Windows own DC")
self.max_using_full_screen_hint_check_box = self.create_checkbox(
"Maximize using full screen"
)
layout = QtWidgets.QGridLayout()
layout.addWidget(self.ms_windows_fixed_size_dialog_checkbox, 0, 0)
layout.addWidget(self.ms_windows_own_dc_check_box, 1, 0)
layout.addWidget(self.bypass_window_manager_checkbox, 2, 0)
layout.addWidget(self.x11_bypass_window_manager_checkbox, 3, 0)
layout.addWidget(self.frameless_window_check_box, 4, 0)
layout.addWidget(self.window_no_shadow_check_box, 5, 0)
layout.addWidget(self.customize_window_hint_check_box, 6, 0)
layout.addWidget(self.window_title_check_box, 7, 0)
layout.addWidget(self.window_system_menu_check_box, 8, 0)
layout.addWidget(self.window_minimize_button_check_box, 0, 1)
layout.addWidget(self.window_maximize_button_check_box, 1, 1)
layout.addWidget(self.window_close_button_check_box, 2, 1)
layout.addWidget(self.window_context_help_button_check_box, 3, 1)
layout.addWidget(self.window_stays_on_top_check_box, 4, 1)
layout.addWidget(self.window_shade_button_check_box, 5, 1)
layout.addWidget(self.window_stays_on_bottom_check_box, 6, 1)
layout.addWidget(self.window_transparent_for_input_check_box, 7, 1)
layout.addWidget(self.max_using_full_screen_hint_check_box, 8, 1)
self.hints_group_box.setLayout(layout)
def update_preview(self) -> None:
""" by preview Window settings new flags And redisplay :return: None """
flags = Qt.WindowFlags
if self.window_radiobutton.isChecked():
flags = Qt.Window
elif self.dialog_radiobutton.isChecked():
flags = Qt.Dialog
elif self.sheet_radiobutton.isChecked():
flags = Qt.Sheet
elif self.popup_radiobutton.isChecked():
flags = Qt.Popup
elif self.tool_radiobutton.isChecked():
flags = Qt.Tool
elif self.tool_tip_radiobutton.isChecked():
flags = Qt.ToolTip
elif self.splash_screen_radiobutton.isChecked():
flags = Qt.SplashScreen
elif self.sub_window_radiobutton.isChecked():
flags = Qt.SubWindow
elif self.foreign_window_radiobutton.isChecked():
flags = Qt.ForeignWindow
elif self.cover_window_radiobutton.isChecked():
flags = Qt.CoverWindow
if self.ms_windows_fixed_size_dialog_checkbox.isChecked():
flags |= Qt.MSWindowsFixedSizeDialogHint
if self.bypass_window_manager_checkbox.isChecked():
flags |= Qt.BypassWindowManagerHint
if self.x11_bypass_window_manager_checkbox.isChecked():
flags |= Qt.X11BypassWindowManagerHint
if self.frameless_window_check_box.isChecked():
flags |= Qt.FramelessWindowHint
if self.window_no_shadow_check_box.isChecked():
flags |= Qt.NoDropShadowWindowHint
if self.window_title_check_box.isChecked():
flags |= Qt.WindowTitleHint
if self.window_system_menu_check_box.isChecked():
flags |= Qt.WindowSystemMenuHint
if self.window_minimize_button_check_box.isChecked():
flags |= Qt.WindowMinimizeButtonHint
if self.window_maximize_button_check_box.isChecked():
flags |= Qt.WindowMaximizeButtonHint
if self.window_close_button_check_box.isChecked():
flags |= Qt.WindowCloseButtonHint
if self.window_context_help_button_check_box.isChecked():
flags |= Qt.WindowContextHelpButtonHint
if self.window_shade_button_check_box.isChecked():
flags |= Qt.WindowShadeButtonHint
if self.window_stays_on_top_check_box.isChecked():
flags |= Qt.WindowStaysOnTopHint
if self.window_stays_on_bottom_check_box.isChecked():
flags |= Qt.WindowStaysOnBottomHint
if self.customize_window_hint_check_box.isChecked():
flags |= Qt.CustomizeWindowHint
if self.window_transparent_for_input_check_box.isChecked():
flags |= Qt.WindowTransparentForInput
if self.ms_windows_own_dc_check_box.isChecked():
flags |= Qt.MSWindowsOwnDC
if self.max_using_full_screen_hint_check_box.isChecked():
flags |= Qt.MaximizeUsingFullscreenGeometryHint
self.preview_window.set_window_flags(flags)
# Prevent windows under some platforms from appearing in invisible positions
pos = self.preview_window.pos()
if pos.x() < 0:
pos.setX(0)
if pos.y() < 0:
pos.setY(0)
self.preview_window.move(pos)
self.preview_window.show() # To display preview window
def crate_radiobutton(self, text: str) -> QtWidgets.QRadioButton:
""" Quickly create radio buttons and connect clicked Signal to self.update_preview Slot function \n :param text: The text of the radio button :return: Radio buttons created """
button = QtWidgets.QRadioButton(text)
button.clicked.connect(self.update_preview) # type: ignore
return button
def create_checkbox(self, text: str) -> QtWidgets.QCheckBox:
""" Quickly create check boxes and connect clicked Signal to self.update_preview Slot function \n :param text: Check box text :return: Created checkbox """
checkbox = QtWidgets.QCheckBox(text)
checkbox.clicked.connect(self.update_preview) # type: ignore
return checkbox
class PreviewWindow(QtWidgets.QWidget):
""" Preview window class """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Create a read-only text editor , Used to display the current window status
self.text_edit = QtWidgets.QTextEdit()
self.text_edit.setReadOnly(True)
self.text_edit.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
self.close_button = QtWidgets.QPushButton("&Close")
self.close_button.clicked.connect(self.close) # type: ignore
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.text_edit)
layout.addWidget(self.close_button)
self.setLayout(layout)
self.setWindowTitle("Preview")
def set_window_flags(self, flags: Qt.WindowFlags) -> None:
""" Set the window flag and display it in the text editor \n :param flags: Window marker :return: None """
self.setWindowFlags(flags)
text = "" # Prompt text for display in the window
window_type = flags & Qt.WindowType_Mask
# Set the prompt text of the window type
if window_type == Qt.Window:
text = "Qt.Window"
elif window_type == Qt.Dialog:
text = "Qt.Dialog"
elif window_type == Qt.Sheet:
text = "Qt.Sheet"
elif window_type == Qt.Drawer:
text = "Qt.Drawer"
elif window_type == Qt.Popup:
text = "Qt.Popup"
elif window_type == Qt.Tool:
text = "Qt.Tool"
elif window_type == Qt.ToolTip:
text = "Qt.ToolTip"
elif window_type == Qt.SplashScreen:
text = "Qt.SplashScreen"
elif window_type == Qt.SubWindow:
text = "Qt.SubWindow"
elif window_type == Qt.ForeignWindow:
text = "Qt.ForeignWindow"
elif window_type == Qt.CoverWindow:
text = "Qt.CoverWindow"
# Set the prompt text of the window flag
if flags & Qt.MSWindowsFixedSizeDialogHint:
text += "\n| Qt.MSWindowsFixedSizeDialogHint"
if flags & Qt.BypassWindowManagerHint:
text += "\n| Qt.BypassWindowManagerHint"
if flags & Qt.X11BypassWindowManagerHint:
text += "\n| Qt.X11BypassWindowManagerHint"
if flags & Qt.FramelessWindowHint:
text += "\n| Qt.FramelessWindowHint"
if flags & Qt.NoDropShadowWindowHint:
text += "\n| Qt.NoDropShadowWindowHint"
if flags & Qt.WindowTitleHint:
text += "\n| Qt.WindowTitleHint"
if flags & Qt.WindowSystemMenuHint:
text += "\n| Qt.WindowSystemMenuHint"
if flags & Qt.WindowMinimizeButtonHint:
text += "\n| Qt.WindowMinimizeButtonHint"
if flags & Qt.WindowMaximizeButtonHint:
text += "\n| Qt.WindowMaximizeButtonHint"
if flags & Qt.WindowCloseButtonHint:
text += "\n| Qt.WindowCloseButtonHint"
if flags & Qt.WindowContextHelpButtonHint:
text += "\n| Qt.WindowContextHelpButtonHint"
if flags & Qt.WindowShadeButtonHint:
text += "\n| Qt.WindowShadeButtonHint"
if flags & Qt.WindowStaysOnTopHint:
text += "\n| Qt.WindowStaysOnTopHint"
if flags & Qt.WindowStaysOnBottomHint:
text += "\n| Qt.WindowStaysOnBottomHint"
if flags & Qt.CustomizeWindowHint:
text += "\n| Qt.CustomizeWindowHint"
if flags & Qt.WindowTransparentForInput:
text += "\n| Qt.WindowTransparentForInput"
if flags & Qt.MSWindowsOwnDC:
text += "\n| Qt.MSWindowsOwnDC"
if flags & Qt.MaximizeUsingFullscreenGeometryHint:
text += "\n| Qt.MaximizeUsingFullscreenGeometryHint"
self.text_edit.setPlainText(text)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = ControllerWindow()
window.show()
sys.exit(app.exec())
边栏推荐
- LVM logical volume group management
- Implementation of simple matcap+fresnel shader in unity
- Solve the problem that CSDN cannot publish blog due to unknown copyright
- Solve the problem that the disk is full due to large files
- [flask introduction series] installation and configuration of flask Sqlalchemy
- [skill accumulation] presentation practical skill accumulation, common sentence patterns
- The software package is set to - > Yum source
- An optimal buffer management scheme with dynamic thresholds paper summary
- Data unit: bit, byte, word, word length
- [dry goods memo] 50 kinds of Matplotlib scientific research paper drawing collection, including code implementation
猜你喜欢

Mqtt server setup and mqtt.fx testing

Matrix decomposition and gradient descent

Day 014 二维数组练习

Ionicons icon Encyclopedia

Alibaba political commissar system - Chapter 4: political commissars are built on companies

【学术相关】为什么很多国内学者的AI的论文复现不了?

Tb6600+stm32f407 test

Arduino uno error analysis avrdude: stk500_ recv(): programmer is not responding

Official tutorial redshift 01 basic theoretical knowledge and basic characteristics learning

STM32 detection signal frequency
随机推荐
Jiamusi Market Supervision Bureau carried out special food safety network training on epidemic and insect prevention
[beauty of software engineering - column notes] 24 | technical debt: continue to make do with it, or overthrow it and start over?
Official tutorial redshift 01 basic theoretical knowledge and basic characteristics learning
在一个sql文件中,上面定义一个测试表及数据,下面可以select* from 测试表
Some simple uses of crawler requests Library
Mqtt server setup and mqtt.fx testing
[experience] relevant configuration of remote connection to intranet server through springboard machine
Resize2fs: bad magic number in super block
[skill accumulation] common expressions when writing emails
[cryoelectron microscope] relation4.0 - subtomogram tutorial
Go 事,如何成为一个Gopher ,并在7天找到 Go 语言相关工作,第1篇
Database persistence +jdbc database connection
Unity beginner 4 - frame animation and protagonist attack (2D)
Ansible (automation software)
[paper reading | cryoelectron microscope] interpretation of the new subtomogram averaging method in relion 4.0
[beauty of software engineering - column notes] 22 | how to do a good job in technology selection for the project?
Internet worm
[introduction to cryoelectron microscopy] Caltech open class course notes part 3:image formation
Some thoughts on growing into an architect
Data unit: bit, byte, word, word length