madgui.util.qt module¶
Miscellaneous utilities for programming with the Qt framework.
Functions
|
Connect the handler function to be called when the widget receives an event specified by the given name. |
|
Subscribe to events from |
|
Activate window and bring to front. |
Return a fixed-space |
|
|
Return a bold |
|
Initialize widget from |
|
Load an icon distributed with the given python package. |
Classes
|
Implements an event filter from a lookup table. |
|
Decorator for widget constructor methods. |
|
A queued trigger. |
-
class
madgui.util.qt.
EventFilter
(events, parent=None)[source]¶ Bases:
PyQt5.QtCore.QObject
Implements an event filter from a lookup table. It is preferred to use the
eventFilter()
function rather than instanciating this class directly.Methods
eventFilter
(self, QObject, QEvent)
-
class
madgui.util.qt.
Queued
(func)[source]¶ Bases:
object
A queued trigger. Calling the trigger will invoke the handler function in another mainloop iteration.
Calling the trigger multiple times before the handler was invoked (e.g. within the same mainloop iteration) will result in only a single handler invocation!
This can only be used with at least a
QCoreApplication
instanciated.Methods
method
(func)Decorator for a queued method, i.e.
-
class
madgui.util.qt.
SingleWindow
(construct)[source]¶ Bases:
madgui.util.qt.Property
Decorator for widget constructor methods. It manages the lifetime of the widget to ensure that only one is active at the same time.
-
madgui.util.qt.
eventFilter
(object, events, parent=None)[source]¶ Subscribe to events from
object
and dispatch viaevents
lookup table. Callbacks are invoked with two parameters(object, event)
and should return a false-ish value. A true-ish value will stop the event from being processed further.Example usage:
>>> self.event_filter = eventFilter(window, { ... 'WindowActivate': self._on_window_activate, ... 'Close': self._on_window_close)) ... })
(Note that it is important to store the reference to the event filter somewhere - otherwise it may be garbage collected.)
See
QEvent
for possible events.
-
madgui.util.qt.
load_icon_resource
(module, name, format='XPM')[source]¶ Load an icon distributed with the given python package. Returns a
QPixmap
.
-
madgui.util.qt.
load_ui
(widget, package, filename)[source]¶ Initialize widget from
.uic
file loaded from the given package.This function is for loading GUIs that were developed using the qt-designer rapid development tool which creates
.uic
description files. These can be saved in the same package alongside the corresponding python code. Now, in the class that implements the widget, use this function as follows:class MyWidget(QWidget): def __init__(self): super().__init__() load_ui(self, __package__, 'mywidget.uic')