mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix Qt stylesheets getting duplicated over and over again (#2083)
This commit is contained in:
parent
cfb309e6b3
commit
abb018b507
2 changed files with 36 additions and 48 deletions
|
@ -26,8 +26,8 @@ qlineargradient(
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def general_styles(tm: ThemeManager, buf: str) -> str:
|
def general_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QFrame {{
|
QFrame {{
|
||||||
background: none;
|
background: none;
|
||||||
}}
|
}}
|
||||||
|
@ -59,11 +59,10 @@ QToolTip {{
|
||||||
background: {tm.var(colors.CANVAS_OVERLAY)};
|
background: {tm.var(colors.CANVAS_OVERLAY)};
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def button_styles(tm: ThemeManager, buf: str) -> str:
|
def button_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QPushButton,
|
QPushButton,
|
||||||
QTabBar::tab:!selected,
|
QTabBar::tab:!selected,
|
||||||
QComboBox:!editable {{
|
QComboBox:!editable {{
|
||||||
|
@ -96,11 +95,10 @@ QComboBox:!editable:pressed {{
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def splitter_styles(tm: ThemeManager, buf: str) -> str:
|
def splitter_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QSplitter::handle,
|
QSplitter::handle,
|
||||||
QMainWindow::separator {{
|
QMainWindow::separator {{
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
@ -114,11 +112,10 @@ QMainWindow::separator:vertical {{
|
||||||
image: url({tm.themed_icon("mdi:drag-vertical-FG_SUBTLE")});
|
image: url({tm.themed_icon("mdi:drag-vertical-FG_SUBTLE")});
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def combobox_styles(tm: ThemeManager, buf: str) -> str:
|
def combobox_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QComboBox {{
|
QComboBox {{
|
||||||
padding: 1px 4px 2px 6px;
|
padding: 1px 4px 2px 6px;
|
||||||
}}
|
}}
|
||||||
|
@ -175,11 +172,10 @@ QComboBox::drop-down:hover {{
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def tabwidget_styles(tm: ThemeManager, buf: str) -> str:
|
def tabwidget_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QTabWidget {{
|
QTabWidget {{
|
||||||
border-radius: {tm.var(props.BORDER_RADIUS)};
|
border-radius: {tm.var(props.BORDER_RADIUS)};
|
||||||
background: none;
|
background: none;
|
||||||
|
@ -223,11 +219,10 @@ QTabBar::tab:selected {{
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def table_styles(tm: ThemeManager, buf: str) -> str:
|
def table_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QTableView {{
|
QTableView {{
|
||||||
border-radius: {tm.var(props.BORDER_RADIUS)};
|
border-radius: {tm.var(props.BORDER_RADIUS)};
|
||||||
gridline-color: {tm.var(colors.BORDER)};
|
gridline-color: {tm.var(colors.BORDER)};
|
||||||
|
@ -294,11 +289,10 @@ QHeaderView::down-arrow {{
|
||||||
image: url({tm.themed_icon("mdi:menu-down")});
|
image: url({tm.themed_icon("mdi:menu-down")});
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def spinbox_styles(tm: ThemeManager, buf: str) -> str:
|
def spinbox_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QSpinBox::up-button,
|
QSpinBox::up-button,
|
||||||
QSpinBox::down-button {{
|
QSpinBox::down-button {{
|
||||||
subcontrol-origin: border;
|
subcontrol-origin: border;
|
||||||
|
@ -370,11 +364,10 @@ QSpinBox::down-arrow:off {{
|
||||||
image: url({tm.themed_icon("mdi:chevron-down-FG_DISABLED")});
|
image: url({tm.themed_icon("mdi:chevron-down-FG_DISABLED")});
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def checkbox_styles(tm: ThemeManager, buf: str) -> str:
|
def checkbox_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QCheckBox {{
|
QCheckBox {{
|
||||||
spacing: 8px;
|
spacing: 8px;
|
||||||
margin: 2px 0;
|
margin: 2px 0;
|
||||||
|
@ -399,11 +392,10 @@ QCheckBox::indicator:indeterminate {{
|
||||||
image: url({tm.themed_icon("mdi:minus-thick")});
|
image: url({tm.themed_icon("mdi:minus-thick")});
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def scrollbar_styles(tm: ThemeManager, buf: str) -> str:
|
def scrollbar_styles(tm: ThemeManager) -> str:
|
||||||
buf += f"""
|
return f"""
|
||||||
QAbstractScrollArea::corner {{
|
QAbstractScrollArea::corner {{
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
|
@ -443,32 +435,28 @@ QScrollBar::sub-line {{
|
||||||
background: none;
|
background: none;
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
return buf
|
|
||||||
|
|
||||||
|
|
||||||
def win10_styles(tm: ThemeManager, buf: str) -> str:
|
def win10_styles(tm: ThemeManager) -> str:
|
||||||
|
styles = f"""
|
||||||
# day mode is missing a bottom border; background must be
|
/* day mode is missing a bottom border; background must be
|
||||||
# also set for border to apply
|
also set for border to apply */
|
||||||
buf += f"""
|
|
||||||
QMenuBar {{
|
QMenuBar {{
|
||||||
border-bottom: 1px solid {tm.var(colors.BORDER)};
|
border-bottom: 1px solid {tm.var(colors.BORDER)};
|
||||||
background: {tm.var(colors.CANVAS) if tm.night_mode else "white"};
|
background: {tm.var(colors.CANVAS) if tm.night_mode else "white"};
|
||||||
}}
|
}}
|
||||||
"""
|
|
||||||
|
|
||||||
# qt bug? setting the above changes the browser sidebar
|
/* qt bug? setting the above changes the browser sidebar
|
||||||
# to white as well, so set it back
|
to white as well, so set it back */
|
||||||
buf += f"""
|
|
||||||
QTreeWidget {{
|
QTreeWidget {{
|
||||||
background: {tm.var(colors.CANVAS)};
|
background: {tm.var(colors.CANVAS)};
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if tm.night_mode:
|
if tm.night_mode:
|
||||||
buf += """
|
styles += """
|
||||||
QToolTip {
|
QToolTip {
|
||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
return buf
|
return styles
|
||||||
|
|
|
@ -206,7 +206,7 @@ class ThemeManager:
|
||||||
def _apply_style(self, app: QApplication) -> None:
|
def _apply_style(self, app: QApplication) -> None:
|
||||||
from aqt.stylesheets import splitter_styles
|
from aqt.stylesheets import splitter_styles
|
||||||
|
|
||||||
buf = splitter_styles(self, "")
|
buf = splitter_styles(self)
|
||||||
|
|
||||||
if not is_mac:
|
if not is_mac:
|
||||||
from aqt.stylesheets import (
|
from aqt.stylesheets import (
|
||||||
|
@ -223,19 +223,19 @@ class ThemeManager:
|
||||||
|
|
||||||
buf += "".join(
|
buf += "".join(
|
||||||
[
|
[
|
||||||
general_styles(self, buf),
|
general_styles(self),
|
||||||
button_styles(self, buf),
|
button_styles(self),
|
||||||
combobox_styles(self, buf),
|
combobox_styles(self),
|
||||||
tabwidget_styles(self, buf),
|
tabwidget_styles(self),
|
||||||
table_styles(self, buf),
|
table_styles(self),
|
||||||
spinbox_styles(self, buf),
|
spinbox_styles(self),
|
||||||
checkbox_styles(self, buf),
|
checkbox_styles(self),
|
||||||
scrollbar_styles(self, buf),
|
scrollbar_styles(self),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_win and platform.release() == "10":
|
if is_win and platform.release() == "10":
|
||||||
buf += win10_styles(self, buf)
|
buf += win10_styles(self)
|
||||||
|
|
||||||
# allow addons to modify the styling
|
# allow addons to modify the styling
|
||||||
buf = gui_hooks.style_did_init(buf)
|
buf = gui_hooks.style_did_init(buf)
|
||||||
|
|
Loading…
Reference in a new issue