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 icon

  • image_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:

str

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 are PySide6.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 or top, the respective boundary is returned.

Parameters:

value (str) – Value to be fixed.

Returns:

value – Value that has been fixed.

Return type:

str

class State(value)

Bases: Enum

An enumeration.

Invalid = 0
Intermediate = 1
Acceptable = 2
blockSignals(self, b: bool) bool
bottom(self) int
bottomChanged
changed
childEvent(self, event: PySide6.QtCore.QChildEvent) None
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
connectNotify(self, signal: PySide6.QtCore.QMetaMethod) None
customEvent(self, event: PySide6.QtCore.QEvent) None
deleteLater(self) None
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
disconnectNotify(self, signal: PySide6.QtCore.QMetaMethod) None
dumpObjectInfo(self) None
dumpObjectTree(self) None
dynamicPropertyNames(self) List[PySide6.QtCore.QByteArray]
emit(self, arg__1: bytes, *args: None) bool
event(self, event: PySide6.QtCore.QEvent) bool
eventFilter(self, watched: PySide6.QtCore.QObject, event: PySide6.QtCore.QEvent) bool
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
inherits(self, classname: bytes) bool
installEventFilter(self, filterObj: PySide6.QtCore.QObject) None
isQuickItemType(self) bool
isSignalConnected(self, signal: PySide6.QtCore.QMetaMethod) bool
isWidgetType(self) bool
isWindowType(self) bool
killTimer(self, id: int) None
locale(self) PySide6.QtCore.QLocale
metaObject(self) PySide6.QtCore.QMetaObject
moveToThread(self, thread: PySide6.QtCore.QThread) None
objectName(self) str
objectNameChanged
parent(self) PySide6.QtCore.QObject
property(self, name: str) Any
receivers(self, signal: bytes) int
removeEventFilter(self, obj: PySide6.QtCore.QObject) None
sender(self) PySide6.QtCore.QObject
senderSignalIndex(self) int
setBottom(self, arg__1: int) None
setLocale(self, locale: PySide6.QtCore.QLocale | PySide6.QtCore.QLocale.Language) None
setObjectName(self, name: str) None
setParent(self, parent: PySide6.QtCore.QObject | None) None
setProperty(self, name: str, value: Any) bool
setRange(self, bottom: int, top: int) None
setTop(self, arg__1: int) None
signalsBlocked(self) bool
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
timerEvent(self, event: PySide6.QtCore.QTimerEvent) None
top(self) int
topChanged
tr(self, sourceText: str, disambiguation: str | None, n: int = -1) str
validate(self, arg__1: str, arg__2: int) object