Revert QComboBox stylesheet override

This commit is contained in:
Matthias Metelka 2022-08-18 09:56:06 +02:00
parent ac4c88afdc
commit b6f9c9a64e
4 changed files with 26 additions and 30 deletions

View file

@ -6,7 +6,9 @@ from __future__ import annotations
import aqt import aqt
import aqt.browser import aqt.browser
import aqt.gui_hooks import aqt.gui_hooks
from aqt import colors
from aqt.qt import * from aqt.qt import *
from aqt.theme import theme_manager
class SidebarSearchBar(QLineEdit): class SidebarSearchBar(QLineEdit):
@ -18,10 +20,29 @@ class SidebarSearchBar(QLineEdit):
self.timer.setInterval(600) self.timer.setInterval(600)
self.timer.setSingleShot(True) self.timer.setSingleShot(True)
self.setFrame(False) self.setFrame(False)
self.setup_style()
qconnect(self.timer.timeout, self.onSearch) qconnect(self.timer.timeout, self.onSearch)
qconnect(self.textChanged, self.onTextChanged) qconnect(self.textChanged, self.onTextChanged)
aqt.gui_hooks.theme_did_change.append(self.setup_style)
def setup_style(self) -> None:
styles = [
"padding: 2px",
f"border: 1px solid {theme_manager.color(colors.BORDER)}",
"border-radius: 5px",
]
self.setStyleSheet(
"QLineEdit { %s }" % ";".join(styles)
+ f"""
QLineEdit:focus {{
border: 1px solid {theme_manager.color(colors.FOCUS_BORDER)};
}}
"""
)
def onTextChanged(self, text: str) -> None: def onTextChanged(self, text: str) -> None:
if not self.timer.isActive(): if not self.timer.isActive():
self.timer.start() self.timer.start()
@ -36,3 +57,6 @@ class SidebarSearchBar(QLineEdit):
self.onSearch() self.onSearch()
else: else:
QLineEdit.keyPressEvent(self, evt) QLineEdit.keyPressEvent(self, evt)
def cleanup(self) -> None:
aqt.gui_hooks.theme_did_change.remove(self.setup_style)

View file

@ -116,6 +116,7 @@ class SidebarTreeView(QTreeView):
def cleanup(self) -> None: def cleanup(self) -> None:
self.toolbar.cleanup() self.toolbar.cleanup()
self.searchBar.cleanup()
gui_hooks.flag_label_did_change.remove(self.refresh) gui_hooks.flag_label_did_change.remove(self.refresh)
gui_hooks.theme_did_change.remove(self._setup_style) gui_hooks.theme_did_change.remove(self._setup_style)

View file

@ -33,9 +33,6 @@ copy_mdi_icons(
# tags # tags
"tag-outline.svg", "tag-outline.svg",
"tag-off-outline.svg", "tag-off-outline.svg",
# QComboBox arrow
"chevron-down.svg",
], ],
) )

View file

@ -186,33 +186,7 @@ class ThemeManager:
gui_hooks.theme_did_change() gui_hooks.theme_did_change()
def _apply_style(self, app: QApplication) -> None: def _apply_style(self, app: QApplication) -> None:
buf = f""" buf = ""
QComboBox,
QLineEdit {{
border: 1px solid {self.color(colors.BORDER)};
border-radius: 5px;
padding: 2px;
}}
QComboBox:focus,
QLineEdit:focus {{
border: 1px solid {self.color(colors.FOCUS_BORDER)};
}}
QComboBox:on {{
border-bottom: none;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}}
QComboBox::drop-down {{
border: 0px; /* This resets the arrow styles */
subcontrol-origin: padding;
padding: 4px;
subcontrol-position: top right;
width: 18px;
}}
QComboBox::down-arrow {{
image: url(icons:chevron-down.svg);
}}
"""
if is_win and platform.release() == "10": if is_win and platform.release() == "10":
# day mode is missing a bottom border; background must be # day mode is missing a bottom border; background must be