qtbricks.utils module
General utils of the qtbricks package.
Mostly small functions that are more general and get used in the other modules. Some of these functions may be useful for packages importing qtbricks, hence generally the individual functions are designed with reusability beyond the qtbricks package in mind.
- qtbricks.utils.image_path(name='', image_dir='images', base_dir='')
Return full path to a given image.
Images, such as icons, are used in several places in GUIs, but are usually stored in a separate directory. Hence, a generic function returning the full path is both, convenient and modular.
If the internal organisation of images changes, only this code needs to be adapted.
For use with own packages, you may want to set the parameter
base_dir
accordingly.- Parameters:
name (
str
) – Name of the iconimage_dir (
str
) –Directory containing the icons
Default: “images”
base_dir (
str
) –Directory used as base for the icons directory
Useful in cases where the function should be used outside this package, i.e. with a different base directory for the images.
Default:
os.path.dirname(__file__)
- Returns:
path – Full path to the icon
- Return type:
- qtbricks.utils.create_button(text='', slot=None, shortcut='', icon='', checkable=False, tooltip='')
Conveniently create a button.
- Parameters:
text (
str
) –The text appearing on the button.
In case you provide both, icon (see below) and text, both are displayed. If you intend to only present an icon, set the text to an empty string.
Default: empty
slot (
function
) – The slot to connect to the button.shortcut (
str
) –The keyboard shortcut used for the action connected to the button.
Default: empty
icon (
str
) –The name of the icon file to be used.
If empty, no icon will be displayed.
For enhanced modularity, do not provide paths, but only icon file names, as the full path will get looked up using the
icon_path()
function.checkable (
bool
) – Whether the button is checkable, i.e., displays its current state.tooltip (class:str) –
Tooltip to be displayed for the button.
Sensible tooltips go a long way towards a user-friendly GUI.
- Returns:
button
- Return type:
QtWidgets.QPushButton
- qtbricks.utils.make_buttons_in_group_uncheckable(buttongroup)
Allow all buttons in exclusive button group to be unchecked.
By default, an exclusive button group does not allow to uncheck all buttons by clicking the selected button, but only to select an alternative button, once one button has been clicked.
- Parameters:
buttongroup (
QtWidgets.QButtonGroup
) – Button group to operate on
- class qtbricks.utils.IntValidator
Bases:
QIntValidator
Integer validator actually fixing input that is beyond the boundaries.
The standard Qt integer validator (actually the base class of this class) has an empty fixup method. Here, the fixup sets text exceeding the set boundaries to the respective boundary.
Examples
A typical use case of the
IntValidator
class arePySide6.QtWidgets.QLineEdit
widgets:line_edit = QtWidgets.QLineEdit() validator = IntValidator(0, 42) line_edit.setValidator(validator)
In this case, if the user enters values smaller than 0 or larger than 42, the actual value of the line edit will be set to the respective boundary.
- fixup(value)
Attempt to change input to be valid according to the validator rules.
In case the value exceeds the lower or upper boundary defined by
bottom
ortop
, the respective boundary is returned.
- bottomChanged
- changed
- children(self) List[PySide6.QtCore.QObject]
- static connect(arg__1: PySide6.QtCore.QObject, arg__2: bytes, arg__3: Callable, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) PySide6.QtCore.QMetaObject.Connection
- static connect(self, arg__1: bytes, arg__2: Callable, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) PySide6.QtCore.QMetaObject.Connection
- static connect(self, arg__1: bytes, arg__2: PySide6.QtCore.QObject, arg__3: bytes, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) PySide6.QtCore.QMetaObject.Connection
- static connect(self, sender: PySide6.QtCore.QObject, signal: bytes, member: bytes, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) PySide6.QtCore.QMetaObject.Connection
- static connect(sender: PySide6.QtCore.QObject, signal: PySide6.QtCore.QMetaMethod, receiver: PySide6.QtCore.QObject, method: PySide6.QtCore.QMetaMethod, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) PySide6.QtCore.QMetaObject.Connection
- static connect(sender: PySide6.QtCore.QObject, signal: bytes, receiver: PySide6.QtCore.QObject, member: bytes, type: PySide6.QtCore.Qt.ConnectionType = Instance(Qt.AutoConnection)) PySide6.QtCore.QMetaObject.Connection
- destroyed
- static disconnect(arg__1: PySide6.QtCore.QMetaObject.Connection) bool
- static disconnect(arg__1: PySide6.QtCore.QObject, arg__2: bytes, arg__3: Callable) bool
- static disconnect(self, arg__1: bytes, arg__2: Callable) bool
- static disconnect(self, receiver: PySide6.QtCore.QObject, member: bytes | None = None) bool
- static disconnect(self, signal: bytes, receiver: PySide6.QtCore.QObject, member: bytes) bool
- static disconnect(sender: PySide6.QtCore.QObject, signal: PySide6.QtCore.QMetaMethod, receiver: PySide6.QtCore.QObject, member: PySide6.QtCore.QMetaMethod) bool
- static disconnect(sender: PySide6.QtCore.QObject, signal: bytes, receiver: PySide6.QtCore.QObject, member: bytes) bool
- dynamicPropertyNames(self) List[PySide6.QtCore.QByteArray]
- findChild(self, type: type, name: str = {}, options: PySide6.QtCore.Qt.FindChildOption = Instance(Qt.FindChildrenRecursively)) object
- findChildren(self, type: type, name: str = {}, options: PySide6.QtCore.Qt.FindChildOption = Instance(Qt.FindChildrenRecursively)) Iterable
- findChildren(self, type: type, pattern: PySide6.QtCore.QRegularExpression | str, options: PySide6.QtCore.Qt.FindChildOption = Instance(Qt.FindChildrenRecursively)) Iterable
- locale(self) PySide6.QtCore.QLocale
- metaObject(self) PySide6.QtCore.QMetaObject
- objectNameChanged
- parent(self) PySide6.QtCore.QObject
- sender(self) PySide6.QtCore.QObject
- startTimer(self, interval: int, timerType: PySide6.QtCore.Qt.TimerType = Instance(Qt.CoarseTimer)) int
- staticMetaObject = PySide6.QtCore.QMetaObject("IntValidator" inherits "QIntValidator": )
- thread(self) PySide6.QtCore.QThread
- topChanged