now i make Some application using PYQT5.
i want minimize my app , when button clicked that you can see under the picture.
how to i make minimize button or how to action minimize.
now i make Some application using PYQT5.
i want minimize my app , when button clicked that you can see under the picture.
how to i make minimize button or how to action minimize.
For QDialog there are options under setWindowsFlag where you can set whether the minimize and maximize button to be visible or hidden. By default they are set to be hidden.
dialog.setWindowFlag(Qt.WindowMinimizeButtonHint, True)
dialog.setWindowFlag(Qt.WindowMaximizeButtonHint, True)
for minimizing and maximizing respectively
TL;DR: The OS or platform's windowing-system is responsible of drawing the window-icons/-buttons as well as primary event-handling for actions "minimize", "maximize", etc. Some QtWidgets like QDialog
have predefined window-flags. The desired window-buttons can be set using widget.setWindowFlag(flags | Qt.WindowMinimizeButtonHint)
Note: The recommended way of drawing windows is using QtWidget
or QQuickWindow
.
See QWindow — PyQt v5.15 Reference Guide, description:
The
QWindow
class represents a window in the underlying windowing system.A window that is supplied a parent becomes a native child window of their parent window.
An application will typically use
QWidget
orQQuickView
for its UI, and notQWindow
directly. Still,
(formatting and emphasize mine)
Search the docs in PyQt for "minimized".
Like QWindow
the QtWidget
, which QDialog
inherits from, has several event-handling methods supporting minimized
state:
minimized
propertyshowMinimized()
functionBut no explicit method or property to draw this window-button for the Window action "minimize".
The appearance and rendering, as well as modifier-buttons shown in the window-edges depends on the Platform/OS and windowing-system (like e.g. Linux's X-Window system X11 and deployed window-manager).
WindowFlags
Window Flags Example | Qt Widgets 5.15.7:
A widget's flags are stored in a Qt::WindowFlags type which stores an OR combination of the flags.
In PyQt this is implemented using the class QtCore.Qt.WindowFlags
which is a set of the QtCore.Qt.WindowType
enum:
The
CustomizeWindowHint
flag is used to enable customization of the window controls. This flag must be set to allow theWindowTitleHint
,WindowSystemMenuHint
,WindowMinimizeButtonHint
,WindowMaximizeButtonHint
andWindowCloseButtonHint
flags to be changed.
These methods of QWindow
support WindowFlags
:
flags() → WindowFlags
setFlags(Union[WindowFlags, WindowType])
And, these methods of QWidget
support WindowFlags
:
__init__(parent: QWidget = None, flags: Union[WindowFlags, WindowType] = Qt.WindowFlags())
windowFlags() → WindowFlags
setWindowFlags(Union[WindowFlags, WindowType])
overrideWindowFlags(Union[WindowFlags, WindowType])
Example:
from PyQt5.QtCore import Qt # WindowFlags, WindowType
window = QQuickWindow(flags=Qt.WindowFlags(Qt.WindowMinimizeButtonHint))
print('current window-flags, represented as int:', window.flags(), int(window.flags()) )
window.setFlags(Qt.WindowFlags(Qt.WindowMaximizeButtonHint))
Prints:
current window-flags, represented as int: <PyQt5.QtCore.WindowFlags object at 0x7fc471d574a8> 16384
Showing the int
representation of WindowFalgs
instance.
Draws:
Dialogs are special type of window. They often are not resizable, can not be minimized or maximized. Sometimes they are bound to the parent-window (see also Modal dialogues).
QDialog
for example has some default flags.
The widget flags
f
are passed on to theQWidget
constructor. If, for example, you don't want a What's This button in the title bar of the dialog, passQt::WindowTitleHint | Qt::WindowSystemMenuHint
inf
.
Example for PyQt's QDialog
where MinimizeWindowButtonHint
is set:
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QDialog
from PyQt5.QtCore import Qt # WindowFlags, WindowType
app = QApplication(sys.argv)
widget = QDialog()
widget.setWindowTitle('QDialog demo')
print('current dialog-flags, represented as int and hex:', widget.windowFlags(), int(widget.windowFlags()), hex(int(widget.windowFlags())) )
widget.setWindowFlags(widget.windowFlags() | Qt.WindowFlags(Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint)
print('after added min&max then dialog-flags, represented as int and hex:', widget.windowFlags(), int(widget.windowFlags()), hex(int(widget.windowFlags())) )
widget.resize(400,100)
widget.show()
sys.exit(app.exec_())
Renders (on Linux/Ubuntu using XFCE windowing-system):
Prints:
current dialog-flags, represented as int and hex: <PyQt5.QtCore.WindowFlags object at 0x7fc6509d10b8> 134295555 0x8013003
after added min&max then dialog-flags, represented as int and hex: <PyQt5.QtCore.WindowFlags object at 0x7fc6509d1198> 134344707 0x801f003
However, the first are the default window-flags for QDialogue
because the class is inherited from QWidget and QWidget.windowFlags
are predefined too:
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
).
If we convert the decimal value of QDialog's default flags 134295554
from decimal to hex we get:
8013002
as hex, in programming languages also written as 0x8013002
.
Compare this to Qt's WindowType
enum constant | hex value | default of QDialog |
---|---|---|
Qt::Window | 0x00000001 |
No |
Qt::Dialog | 0x00000002 | Window |
Yes |
Qt::WindowTitleHint | 0x00001000 |
Yes |
Qt::WindowSystemMenuHint | 0x00002000 |
Yes |
Qt::WindowMinimizeButtonHint | 0x00004000 |
No |
Qt::WindowMaximizeButtonHint | 0x00008000 |
No |
Qt::WindowMinMaxButtonsHint | WindowMinimizeButtonHint | WindowMaximizeButtonHint |
No |
Qt::WindowContextHelpButtonHint | 0x00010000 |
Yes |
Qt::WindowCloseButtonHint | 0x08000000 |
Yes |
When adding all above marked in bold (with last column "Yes") added into one set of flags using boolean OR |
, we get:
0x8013002
as default-flags for QDialog
.
After printing the initial flags, we added both WindowMinimizeButtonHint
and WindowMaximizeButtonHint
using boolean OR:
widget.windowFlags() | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint
So the dialog now has existing QDialog's default-flags (window-buttons) plus additional minimize & maximize buttons.