added nicer SearchBox
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
from PyQt5.QtWidgets import QWidget, QLineEdit, QVBoxLayout
|
from PyQt5.QtWidgets import QWidget, QLineEdit, QVBoxLayout
|
||||||
|
|
||||||
from .dictlistwidget import DictListWidget
|
from .dictlistwidget import DictListWidget
|
||||||
|
from .searchbox import SearchBox
|
||||||
|
|
||||||
|
|
||||||
class DictList(QWidget):
|
class DictList(QWidget):
|
||||||
@ -8,13 +9,12 @@ class DictList(QWidget):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
search = QLineEdit()
|
search = SearchBox()
|
||||||
search.setPlaceholderText("Search...")
|
|
||||||
self.lst = lst = DictListWidget(*args, **kwargs)
|
self.lst = lst = DictListWidget(*args, **kwargs)
|
||||||
|
|
||||||
lay = QVBoxLayout()
|
lay = QVBoxLayout()
|
||||||
lay.setContentsMargins(0, 0, 0, 0)
|
lay.setContentsMargins(0, 0, 0, 0)
|
||||||
lay.setSpacing(2)
|
lay.setSpacing(0)
|
||||||
lay.addWidget(lst)
|
lay.addWidget(lst)
|
||||||
lay.addWidget(search)
|
lay.addWidget(search)
|
||||||
self.setLayout(lay)
|
self.setLayout(lay)
|
||||||
|
50
grum/dictlist/searchbox.py
Normal file
50
grum/dictlist/searchbox.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
from PyQt5.QtCore import Qt
|
||||||
|
from PyQt5.QtWidgets import QWidget, QLineEdit, QPushButton, QHBoxLayout, QStyle
|
||||||
|
|
||||||
|
|
||||||
|
class SearchBox(QWidget):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.txt = txt = QLineEdit(*args, **kwargs)
|
||||||
|
txt.setPlaceholderText("Search...")
|
||||||
|
|
||||||
|
btn = SquareButton()
|
||||||
|
btn.setFlat(True)
|
||||||
|
|
||||||
|
pmap = QStyle.SP_DialogCloseButton
|
||||||
|
icon = self.style().standardIcon(pmap)
|
||||||
|
btn.setIcon(icon)
|
||||||
|
|
||||||
|
lay = QHBoxLayout()
|
||||||
|
lay.setContentsMargins(2, 2, 0, 2)
|
||||||
|
lay.setSpacing(0)
|
||||||
|
lay.addWidget(txt)
|
||||||
|
lay.addWidget(btn)
|
||||||
|
self.setLayout(lay)
|
||||||
|
|
||||||
|
btn.clicked.connect(self.txt.clear)
|
||||||
|
|
||||||
|
|
||||||
|
# behave like encapsulated QLineEdit
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return getattr(self.txt, name)
|
||||||
|
|
||||||
|
|
||||||
|
def keyPressEvent(self, event):
|
||||||
|
key = event.key()
|
||||||
|
if key == Qt.Key_Escape:
|
||||||
|
self.txt.clear()
|
||||||
|
super().keyPressEvent(event)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class SquareButton(QPushButton):
|
||||||
|
|
||||||
|
def resizeEvent(self, e):
|
||||||
|
height = self.height()
|
||||||
|
self.setMinimumWidth(height)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user