mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Use platform-native button layout in dialogs and messageboxes (#3725)
* set button-layout prop in stylesheet * fix lint * check for and use non-default layout on linux before falling back
This commit is contained in:
parent
e98a597b4d
commit
38821372dd
2 changed files with 22 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
# Copyright: Ankitects Pty Ltd and contributors
|
||||
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
from anki.utils import is_win
|
||||
from anki.utils import is_mac, is_win
|
||||
from aqt import colors, props
|
||||
from aqt.theme import ThemeManager
|
||||
|
||||
|
@ -28,6 +28,19 @@ qlineargradient(
|
|||
"""
|
||||
|
||||
|
||||
def button_layout(tm: ThemeManager):
|
||||
# https://doc.qt.io/qt-6/stylesheet-reference.html#button-layout
|
||||
if is_win:
|
||||
return 0
|
||||
elif is_mac:
|
||||
return 1
|
||||
# on linux, use non-default layout if available
|
||||
if tm._default_button_layout:
|
||||
return tm._default_button_layout
|
||||
# fallback to GnomeLayout
|
||||
return 3
|
||||
|
||||
|
||||
class CustomStyles:
|
||||
def general(self, tm: ThemeManager) -> str:
|
||||
return f"""
|
||||
|
@ -201,6 +214,9 @@ class CustomStyles:
|
|||
}}
|
||||
QPushButton:flat {{
|
||||
border: none;
|
||||
}}
|
||||
QDialogButtonBox {{
|
||||
button-layout: {button_layout(tm)};
|
||||
}}
|
||||
"""
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ from aqt.qt import (
|
|||
QPainter,
|
||||
QPalette,
|
||||
QPixmap,
|
||||
QStyle,
|
||||
QStyleFactory,
|
||||
Qt,
|
||||
qtmajor,
|
||||
|
@ -62,6 +63,7 @@ class ThemeManager:
|
|||
_dark_mode_available: bool | None = None
|
||||
_default_style: str | None = None
|
||||
_current_widget_style: WidgetStyle | None = None
|
||||
_default_button_layout: int | None = None
|
||||
|
||||
def rtl(self) -> bool:
|
||||
return is_rtl(anki.lang.current_lang)
|
||||
|
@ -234,6 +236,9 @@ class ThemeManager:
|
|||
style = app.style()
|
||||
assert style is not None
|
||||
self._default_style = style.objectName()
|
||||
self._default_button_layout = style.styleHint(
|
||||
QStyle.StyleHint.SH_DialogButtonLayout
|
||||
)
|
||||
self._apply_palette(app)
|
||||
self._apply_style(app)
|
||||
gui_hooks.theme_did_change()
|
||||
|
|
Loading…
Reference in a new issue