Skip to content

qt #

Qt objects for app_model.

QCommandAction #

QCommandAction(command_id: str, app: Application | str, parent: QObject | None = None)

Bases: QAction

Base QAction for a command id. Can execute the command.

Parameters:

  • command_id (str) –

    Command ID.

  • app (Application | str) –

    Application instance or name of application instance.

  • parent (QObject | None, default: None ) –

    Optional parent widget, by default None

Source code in app_model/backends/qt/_qaction.py
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(
    self,
    command_id: str,
    app: Application | str,
    parent: QObject | None = None,
):
    super().__init__(parent)
    self._app = Application.get_or_create(app) if isinstance(app, str) else app
    self._command_id = command_id
    self.setObjectName(command_id)
    if kb := self._app.keybindings.get_keybinding(command_id):
        self.setShortcut(QKeyBindingSequence(kb.keybinding))
    self.triggered.connect(self._on_triggered)

QCommandRuleAction #

QCommandRuleAction(command_rule: CommandRule, app: Application | str, parent: QObject | None = None, *, use_short_title: bool = False)

Bases: QCommandAction

QAction for a CommandRule.

Parameters:

  • command_rule (CommandRule) –

    CommandRule instance to create an action for.

  • app (Application | str) –

    Application instance or name of application instance.

  • parent (QObject | None, default: None ) –

    Optional parent widget, by default None

  • use_short_title (bool, default: False ) –

    If True, use the short_title of the command rule, if it exists.

Source code in app_model/backends/qt/_qaction.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def __init__(
    self,
    command_rule: CommandRule,
    app: Application | str,
    parent: QObject | None = None,
    *,
    use_short_title: bool = False,
):
    super().__init__(command_rule.id, app, parent)
    self._cmd_rule = command_rule
    if use_short_title and command_rule.short_title:
        self.setText(command_rule.short_title)  # pragma: no cover
    else:
        self.setText(command_rule.title)
    if command_rule.icon:
        self.setIcon(to_qicon(command_rule.icon))
    self.setIconVisibleInMenu(command_rule.icon_visible_in_menu)
    if command_rule.tooltip:
        self.setToolTip(command_rule.tooltip)
    if command_rule.status_tip:
        self.setStatusTip(command_rule.status_tip)
    if command_rule.toggled is not None:
        self.setCheckable(True)
        self._refresh()

update_from_context #

update_from_context(ctx: Mapping[str, object]) -> None

Update the enabled state of this menu item from ctx.

Source code in app_model/backends/qt/_qaction.py
 98
 99
100
101
102
103
104
105
106
107
def update_from_context(self, ctx: Mapping[str, object]) -> None:
    """Update the enabled state of this menu item from `ctx`."""
    self.setEnabled(expr.eval(ctx) if (expr := self._cmd_rule.enablement) else True)
    if expr2 := self._cmd_rule.toggled:
        if (
            isinstance(expr2, Expr)
            or isinstance(expr2, ToggleRule)
            and (expr2 := expr2.condition)
        ):
            self.setChecked(expr2.eval(ctx))

QKeyBindingSequence #

QKeyBindingSequence(kb: KeyBinding)

Bases: QKeySequence

A QKeySequence based on a KeyBinding instance.

Source code in app_model/backends/qt/_qkeymap.py
106
107
108
def __init__(self, kb: KeyBinding) -> None:
    ints = [simple_keybinding_to_qint(skb) for skb in kb.parts]
    super().__init__(*ints)

QMenuItemAction #

QMenuItemAction(menu_item: MenuItem, app: Application | str, parent: QObject | None = None)

Bases: QCommandRuleAction

QAction for a MenuItem.

Mostly the same as a CommandRuleAction, but aware of the menu_item.when clause to toggle visibility.

Parameters:

  • menu_item (MenuItem) –

    MenuItem instance to create an action for.

  • app (Application | str) –

    Application instance or name of application instance.

  • parent (QObject | None, default: None ) –

    Optional parent widget, by default None

Source code in app_model/backends/qt/_qaction.py
138
139
140
141
142
143
144
145
146
147
def __init__(
    self,
    menu_item: MenuItem,
    app: Application | str,
    parent: QObject | None = None,
):
    super().__init__(menu_item.command, app, parent)
    self._menu_item = menu_item
    with contextlib.suppress(NameError):
        self.update_from_context(self._app.context)

create classmethod #

create(menu_item: MenuItem, app: Application | str, parent: QObject | None = None) -> Self

Create a new QMenuItemAction for the given menu item.

Prefer this method over __init__ to ensure that the cache is used, so that:

a1 = QMenuItemAction.create(action, full_app)
a2 = QMenuItemAction.create(action, full_app)
a1 is a2  # True
Source code in app_model/backends/qt/_qaction.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
@classmethod
def create(
    cls,
    menu_item: MenuItem,
    app: Application | str,
    parent: QObject | None = None,
) -> Self:
    """Create a new QMenuItemAction for the given menu item.

    Prefer this method over `__init__` to ensure that the cache is used,
    so that:

    ```python
    a1 = QMenuItemAction.create(action, full_app)
    a2 = QMenuItemAction.create(action, full_app)
    a1 is a2  # True
    ```
    """
    app = Application.get_or_create(app) if isinstance(app, str) else app
    cache_key = QMenuItemAction._cache_key(app, menu_item)
    if cache_key in cls._cache:
        res = cls._cache[cache_key]
        res.setParent(parent)
        return res

    cls._cache[cache_key] = obj = cls(menu_item, app, parent)
    return obj

update_from_context #

update_from_context(ctx: Mapping[str, object]) -> None

Update the enabled/visible state of this menu item from ctx.

Source code in app_model/backends/qt/_qaction.py
181
182
183
184
def update_from_context(self, ctx: Mapping[str, object]) -> None:
    """Update the enabled/visible state of this menu item from `ctx`."""
    super().update_from_context(ctx)
    self.setVisible(expr.eval(ctx) if (expr := self._menu_item.when) else True)

QModelKeyBindingEdit #

Bases: QKeySequenceEdit

Editor for a KeyBinding instance.

This is a QKeySequenceEdit with a method that converts the current keySequence to an app_model KeyBinding instance.

keyBinding #

keyBinding() -> Optional[KeyBinding]

Return app_model KeyBinding instance for the current keySequence.

Source code in app_model/backends/qt/_qkeybindingedit.py
18
19
20
21
22
def keyBinding(self) -> Optional["KeyBinding"]:
    """Return app_model KeyBinding instance for the current keySequence."""
    if self.keySequence().isEmpty():
        return None
    return qkeysequence2modelkeybinding(self.keySequence())

QModelMainWindow #

QModelMainWindow(app: Application | str, parent: QWidget | None = None)

Bases: QMainWindow

QMainWindow with app-model support.

Source code in app_model/backends/qt/_qmainwindow.py
16
17
18
def __init__(self, app: Application | str, parent: QWidget | None = None) -> None:
    super().__init__(parent)
    self._app = Application.get_or_create(app) if isinstance(app, str) else app

addModelToolBar #

addModelToolBar(menu_id: str, *, exclude: Collection[str] | None = None, area: Qt.ToolBarArea | None = None, toolbutton_style: Qt.ToolButtonStyle = Qt.ToolButtonStyle.ToolButtonIconOnly) -> QModelToolBar

Add a tool bar to the main window.

Source code in app_model/backends/qt/_qmainwindow.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def addModelToolBar(
    self,
    menu_id: str,
    *,
    exclude: Collection[str] | None = None,
    area: Qt.ToolBarArea | None = None,
    toolbutton_style: Qt.ToolButtonStyle = Qt.ToolButtonStyle.ToolButtonIconOnly,
) -> QModelToolBar:
    """Add a tool bar to the main window."""
    toolbar = QModelToolBar(menu_id, self._app, exclude=exclude, parent=self)
    toolbar.setToolButtonStyle(toolbutton_style)
    if area is not None:
        self.addToolBar(area, toolbar)
    else:
        self.addToolBar(toolbar)
    return toolbar

setModelMenuBar #

setModelMenuBar(menu_ids: Mapping[str, str] | Sequence[str | tuple[str, str]]) -> QModelMenuBar

Set the menu bar to a list of menu ids.

Parameters:

Source code in app_model/backends/qt/_qmainwindow.py
20
21
22
23
24
25
26
27
28
29
30
31
32
def setModelMenuBar(
    self, menu_ids: Mapping[str, str] | Sequence[str | tuple[str, str]]
) -> QModelMenuBar:
    """Set the menu bar to a list of menu ids.

    Parameters
    ----------
    menu_ids : Mapping[str, str] | Sequence[str | tuple[str, str]]
        A mapping of menu ids to menu titles or a sequence of menu ids.
    """
    menu_bar = QModelMenuBar(menu_ids, self._app, self)
    self.setMenuBar(menu_bar)
    return menu_bar

QModelMenu #

QModelMenu(menu_id: str, app: Application | str, title: str | None = None, parent: QWidget | None = None)

Bases: QMenu

QMenu for a menu_id in an app_model MenusRegistry.

Parameters:

  • menu_id (str) –

    Menu ID to look up in the registry.

  • app (Application | str) –

    Application instance or name of application instance.

  • title (str | None, default: None ) –

    Optional title for the menu, by default None

  • parent (QWidget | None, default: None ) –

    Optional parent widget, by default None

Source code in app_model/backends/qt/_qmenu.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def __init__(
    self,
    menu_id: str,
    app: Application | str,
    title: str | None = None,
    parent: QWidget | None = None,
):
    QMenu.__init__(self, parent)

    # NOTE: code duplication with QModelToolBar, but Qt mixins and multiple
    # inheritance are problematic for some versions of Qt, and for typing
    assert isinstance(menu_id, str), f"Expected str, got {type(menu_id)!r}"
    self._menu_id = menu_id
    self._app = Application.get_or_create(app) if isinstance(app, str) else app
    self.setObjectName(menu_id)
    self.rebuild()
    self._app.menus.menus_changed.connect(self._on_registry_changed)
    self.destroyed.connect(self._disconnect)
    # ----------------------

    if title is not None:
        self.setTitle(title)
    self.aboutToShow.connect(self._on_about_to_show)

findAction #

findAction(object_name: str) -> QAction | QModelMenu | None

Find an action by its ObjectName.

Parameters:

  • object_name (str) –

    Action ID to find. Note that QCommandAction have ObjectName set to their command.id

Source code in app_model/backends/qt/_qmenu.py
62
63
64
65
66
67
68
69
70
71
def findAction(self, object_name: str) -> QAction | QModelMenu | None:
    """Find an action by its ObjectName.

    Parameters
    ----------
    object_name : str
        Action ID to find. Note that `QCommandAction` have `ObjectName` set
        to their `command.id`
    """
    return _find_action(self.actions(), object_name)

rebuild #

rebuild(include_submenus: bool = True, exclude: Collection[str] | None = None) -> None

Rebuild menu by looking up self._menu_id in menu_registry.

Source code in app_model/backends/qt/_qmenu.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def rebuild(
    self, include_submenus: bool = True, exclude: Collection[str] | None = None
) -> None:
    """Rebuild menu by looking up self._menu_id in menu_registry."""
    _rebuild(
        menu=self,
        app=self._app,
        menu_id=self._menu_id,
        include_submenus=include_submenus,
        exclude=exclude,
    )

update_from_context #

update_from_context(ctx: Mapping[str, object], _recurse: bool = True) -> None

Update the enabled/visible state of each menu item with ctx.

See app_model.expressions for details on expressions.

Parameters:

  • ctx (Mapping) –

    A namespace that will be used to eval() the 'enablement' and 'when' expressions provided for each action in the menu. ALL variables used in these expressions must either be present in the ctx dict, or be builtins.

  • _recurse (bool, default: True ) –

    recursion check, internal use only

Source code in app_model/backends/qt/_qmenu.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def update_from_context(
    self, ctx: Mapping[str, object], _recurse: bool = True
) -> None:
    """Update the enabled/visible state of each menu item with `ctx`.

    See `app_model.expressions` for details on expressions.

    Parameters
    ----------
    ctx : Mapping
        A namespace that will be used to `eval()` the `'enablement'` and
        `'when'` expressions provided for each action in the menu.
        *ALL variables used in these expressions must either be present in
        the `ctx` dict, or be builtins*.
    _recurse : bool
        recursion check, internal use only
    """
    _update_from_context(self.actions(), ctx, _recurse=_recurse)

QModelMenuBar #

QModelMenuBar(menus: Mapping[str, str] | Sequence[str | tuple[str, str]], app: Application | str, parent: QWidget | None = None)

Bases: QMenuBar

QMenuBar that is built from a list of model menu ids.

Parameters:

  • menus (Mapping[str, str] | Sequence[str | tuple[str, str]]) –

    A mapping of menu ids to menu titles or a sequence of menu ids.

  • app (Application | str) –

    Application instance or name of application instance.

  • parent (QWidget | None, default: None ) –

    Optional parent widget, by default None

Source code in app_model/backends/qt/_qmenu.py
267
268
269
270
271
272
273
274
275
276
277
278
def __init__(
    self,
    menus: Mapping[str, str] | Sequence[str | tuple[str, str]],
    app: Application | str,
    parent: QWidget | None = None,
) -> None:
    super().__init__(parent)

    menu_items = menus.items() if isinstance(menus, Mapping) else menus
    for item in menu_items:
        id_, title = item if isinstance(item, tuple) else (item, item.title())
        self.addMenu(QModelMenu(id_, app, title, self))

update_from_context #

update_from_context(ctx: Mapping[str, object], _recurse: bool = True) -> None

Update the enabled/visible state of each menu item with ctx.

See app_model.expressions for details on expressions.

Parameters:

  • ctx (Mapping) –

    A namespace that will be used to eval() the 'enablement' and 'when' expressions provided for each action in the menu. ALL variables used in these expressions must either be present in the ctx dict, or be builtins.

  • _recurse (bool, default: True ) –

    recursion check, internal use only

Source code in app_model/backends/qt/_qmenu.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def update_from_context(
    self, ctx: Mapping[str, object], _recurse: bool = True
) -> None:
    """Update the enabled/visible state of each menu item with `ctx`.

    See `app_model.expressions` for details on expressions.

    Parameters
    ----------
    ctx : Mapping
        A namespace that will be used to `eval()` the `'enablement'` and
        `'when'` expressions provided for each action in the menu.
        *ALL variables used in these expressions must either be present in
        the `ctx` dict, or be builtins*.
    _recurse : bool
        recursion check, internal use only
    """
    _update_from_context(self.actions(), ctx, _recurse=_recurse)

QModelSubmenu #

QModelSubmenu(submenu: SubmenuItem, app: Application | str, parent: QWidget | None = None)

Bases: QModelMenu

QMenu for a menu_id in an app_model MenusRegistry.

Parameters:

  • submenu (SubmenuItem) –

    SubmenuItem for which to create a QMenu.

  • app (Application | str) –

    Application instance or name of application instance.

  • parent (QWidget | None, default: None ) –

    Optional parent widget, by default None

Source code in app_model/backends/qt/_qmenu.py
133
134
135
136
137
138
139
140
141
142
143
144
145
def __init__(
    self,
    submenu: SubmenuItem,
    app: Application | str,
    parent: QWidget | None = None,
):
    assert isinstance(submenu, SubmenuItem), f"Expected str, got {type(submenu)!r}"
    self._submenu = submenu
    super().__init__(
        menu_id=submenu.submenu, app=app, title=submenu.title, parent=parent
    )
    if submenu.icon:
        self.setIcon(to_qicon(submenu.icon))

findAction #

findAction(object_name: str) -> QAction | QModelMenu | None

Find an action by its ObjectName.

Parameters:

  • object_name (str) –

    Action ID to find. Note that QCommandAction have ObjectName set to their command.id

Source code in app_model/backends/qt/_qmenu.py
62
63
64
65
66
67
68
69
70
71
def findAction(self, object_name: str) -> QAction | QModelMenu | None:
    """Find an action by its ObjectName.

    Parameters
    ----------
    object_name : str
        Action ID to find. Note that `QCommandAction` have `ObjectName` set
        to their `command.id`
    """
    return _find_action(self.actions(), object_name)

rebuild #

rebuild(include_submenus: bool = True, exclude: Collection[str] | None = None) -> None

Rebuild menu by looking up self._menu_id in menu_registry.

Source code in app_model/backends/qt/_qmenu.py
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def rebuild(
    self, include_submenus: bool = True, exclude: Collection[str] | None = None
) -> None:
    """Rebuild menu by looking up self._menu_id in menu_registry."""
    _rebuild(
        menu=self,
        app=self._app,
        menu_id=self._menu_id,
        include_submenus=include_submenus,
        exclude=exclude,
    )

update_from_context #

update_from_context(ctx: Mapping[str, object], _recurse: bool = True) -> None

Update the enabled state of this menu item from ctx.

Source code in app_model/backends/qt/_qmenu.py
147
148
149
150
151
152
def update_from_context(
    self, ctx: Mapping[str, object], _recurse: bool = True
) -> None:
    """Update the enabled state of this menu item from `ctx`."""
    super().update_from_context(ctx, _recurse=_recurse)
    self.setEnabled(expr.eval(ctx) if (expr := self._submenu.enablement) else True)

QModelToolBar #

QModelToolBar(menu_id: str, app: Application | str, *, exclude: Collection[str] | None = None, title: str | None = None, parent: QWidget | None = None)

Bases: QToolBar

QToolBar that is built from a list of model menu ids.

Parameters:

  • menu_id (str) –

    Menu ID to look up in the registry.

  • app (Application | str) –

    Application instance or name of application instance.

  • exclude (Collection[str] | None, default: None ) –

    Optional list of menu ids to exclude from the toolbar, by default None

  • title (str | None, default: None ) –

    Optional title for the menu, by default None

  • parent (QWidget | None, default: None ) –

    Optional parent widget, by default None

Source code in app_model/backends/qt/_qmenu.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def __init__(
    self,
    menu_id: str,
    app: Application | str,
    *,
    exclude: Collection[str] | None = None,
    title: str | None = None,
    parent: QWidget | None = None,
) -> None:
    self._exclude = exclude
    QToolBar.__init__(self, parent)

    # NOTE: code duplication with QModelMenu, but Qt mixins and multiple
    # inheritance are problematic for some versions of Qt, and for typing
    assert isinstance(menu_id, str), f"Expected str, got {type(menu_id)!r}"
    self._menu_id = menu_id
    self._app = Application.get_or_create(app) if isinstance(app, str) else app
    self.setObjectName(menu_id)
    self.rebuild()
    self._app.menus.menus_changed.connect(self._on_registry_changed)
    self.destroyed.connect(self._disconnect)
    # ----------------------

    if title is not None:
        self.setWindowTitle(title)

addMenu #

addMenu(menu: QMenu) -> None

No-op for toolbar.

Source code in app_model/backends/qt/_qmenu.py
201
202
def addMenu(self, menu: QMenu) -> None:
    """No-op for toolbar."""

findAction #

findAction(object_name: str) -> QAction | QModelMenu | None

Find an action by its ObjectName.

Parameters:

  • object_name (str) –

    Action ID to find. Note that QCommandAction have ObjectName set to their command.id

Source code in app_model/backends/qt/_qmenu.py
204
205
206
207
208
209
210
211
212
213
def findAction(self, object_name: str) -> QAction | QModelMenu | None:
    """Find an action by its ObjectName.

    Parameters
    ----------
    object_name : str
        Action ID to find. Note that `QCommandAction` have `ObjectName` set
        to their `command.id`
    """
    return _find_action(self.actions(), object_name)

rebuild #

rebuild(include_submenus: bool = True, exclude: Collection[str] | None = None) -> None

Rebuild toolbar by looking up self._menu_id in menu_registry.

Source code in app_model/backends/qt/_qmenu.py
234
235
236
237
238
239
240
241
242
243
244
def rebuild(
    self, include_submenus: bool = True, exclude: Collection[str] | None = None
) -> None:
    """Rebuild toolbar by looking up self._menu_id in menu_registry."""
    _rebuild(
        menu=self,
        app=self._app,
        menu_id=self._menu_id,
        include_submenus=include_submenus,
        exclude=self._exclude if exclude is None else exclude,
    )

update_from_context #

update_from_context(ctx: Mapping[str, object], _recurse: bool = True) -> None

Update the enabled/visible state of each menu item with ctx.

See app_model.expressions for details on expressions.

Parameters:

  • ctx (Mapping) –

    A namespace that will be used to eval() the 'enablement' and 'when' expressions provided for each action in the menu. ALL variables used in these expressions must either be present in the ctx dict, or be builtins.

  • _recurse (bool, default: True ) –

    recursion check, internal use only

Source code in app_model/backends/qt/_qmenu.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
def update_from_context(
    self, ctx: Mapping[str, object], _recurse: bool = True
) -> None:
    """Update the enabled/visible state of each menu item with `ctx`.

    See `app_model.expressions` for details on expressions.

    Parameters
    ----------
    ctx : Mapping
        A namespace that will be used to `eval()` the `'enablement'` and
        `'when'` expressions provided for each action in the menu.
        *ALL variables used in these expressions must either be present in
        the `ctx` dict, or be builtins*.
    _recurse : bool
        recursion check, internal use only
    """
    _update_from_context(self.actions(), ctx, _recurse=_recurse)

qkey2modelkey #

qkey2modelkey(key: Qt.Key) -> KeyCode | KeyCombo

Return KeyCode from Qt.Key.

Source code in app_model/backends/qt/_qkeymap.py
294
295
296
297
298
299
300
301
def qkey2modelkey(key: Qt.Key) -> KeyCode | KeyCombo:
    """Return KeyCode from Qt.Key."""
    if MAC and _mac_ctrl_meta_swapped():
        if key == Qt.Key.Key_Control:
            return KeyCode.Meta
        if key == Qt.Key.Key_Meta:
            return KeyCode.Ctrl
    return KEY_FROM_QT.get(key, KeyCode.UNKNOWN)

qkeycombo2modelkey #

qkeycombo2modelkey(key: QKeyCombination) -> KeyCode | KeyCombo

Return KeyCode or KeyCombo from QKeyCombination.

Source code in app_model/backends/qt/_qkeymap.py
304
305
306
307
308
309
310
311
def qkeycombo2modelkey(key: QKeyCombination) -> KeyCode | KeyCombo:
    """Return KeyCode or KeyCombo from QKeyCombination."""
    if key in KEY_FROM_QT:
        # type ignore because in qt5, key may actually just be int ... but it's fine.
        return KEY_FROM_QT[key]
    qmods = _get_qmods(key)
    qkey = _get_qkey(key)
    return qmods2modelmods(qmods) | qkey2modelkey(qkey)  # type: ignore [return-value]

qkeysequence2modelkeybinding #

qkeysequence2modelkeybinding(key: QKeySequence) -> KeyBinding

Return KeyBinding from QKeySequence.

Source code in app_model/backends/qt/_qkeymap.py
314
315
316
317
318
def qkeysequence2modelkeybinding(key: QKeySequence) -> KeyBinding:
    """Return KeyBinding from QKeySequence."""
    # FIXME: this should return KeyChord instead of KeyBinding... but that only takes 2
    parts = [SimpleKeyBinding.from_int(qkeycombo2modelkey(x)) for x in iter(key)]
    return KeyBinding(parts=parts)

qmods2modelmods #

qmods2modelmods(modifiers: Qt.KeyboardModifier) -> KeyMod

Return KeyMod from Qt.KeyboardModifier.

Source code in app_model/backends/qt/_qkeymap.py
272
273
274
275
276
277
278
279
280
281
def qmods2modelmods(modifiers: Qt.KeyboardModifier) -> KeyMod:
    """Return KeyMod from Qt.KeyboardModifier."""
    mod = KeyMod.NONE
    lookup = (
        MAC_KEYMOD_FROM_QT if MAC and not _mac_ctrl_meta_swapped() else KEYMOD_FROM_QT
    )
    for modifier in lookup:
        if modifiers & modifier:
            mod |= lookup[modifier]
    return mod

to_qicon #

to_qicon(icon: Icon, theme: Literal['dark', 'light'] = 'dark') -> QIcon

Create QIcon from Icon.

Source code in app_model/backends/qt/_util.py
13
14
15
16
17
18
19
20
21
22
def to_qicon(icon: Icon, theme: Literal["dark", "light"] = "dark") -> QIcon:
    """Create QIcon from Icon."""
    from superqt import QIconifyIcon, fonticon

    if icn := getattr(icon, theme, ""):
        if ":" in icn:
            return QIconifyIcon(icn)
        else:
            return fonticon.icon(icn)
    return QIcon()  # pragma: no cover