Move custom QLineEdit styles out of searchbar.py

This commit is contained in:
Matthias Metelka 2022-08-16 22:36:10 +02:00
parent 59d618851d
commit e036edd584
2 changed files with 0 additions and 25 deletions

View file

@ -6,9 +6,7 @@ from __future__ import annotations
import aqt
import aqt.browser
import aqt.gui_hooks
from aqt import colors
from aqt.qt import *
from aqt.theme import theme_manager
class SidebarSearchBar(QLineEdit):
@ -20,29 +18,10 @@ class SidebarSearchBar(QLineEdit):
self.timer.setInterval(600)
self.timer.setSingleShot(True)
self.setFrame(False)
self.setup_style()
qconnect(self.timer.timeout, self.onSearch)
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:
if not self.timer.isActive():
self.timer.start()
@ -57,6 +36,3 @@ QLineEdit:focus {{
self.onSearch()
else:
QLineEdit.keyPressEvent(self, evt)
def cleanup(self) -> None:
aqt.gui_hooks.theme_did_change.remove(self.setup_style)

View file

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