E5Gui/E5LineEdit.py

branch
5_2_x
changeset 2200
719cf8ba4743
parent 1509
c0b5e693b0eb
child 2303
0ed4ed026c16
equal deleted inserted replaced
2198:602e28b8bd76 2200:719cf8ba4743
9 9
10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent 10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent
11 from PyQt4.QtGui import QLineEdit, QStyleOptionFrameV2, QStyle, QPainter, QPalette, \ 11 from PyQt4.QtGui import QLineEdit, QStyleOptionFrameV2, QStyle, QPainter, QPalette, \
12 QWidget, QHBoxLayout, QBoxLayout, QLayout, QApplication, QSpacerItem, QSizePolicy 12 QWidget, QHBoxLayout, QBoxLayout, QLayout, QApplication, QSpacerItem, QSizePolicy
13 13
14 14 from E5Gui.E5LineEditButton import E5LineEditButton
15 class SideWidget(QWidget): 15
16 import UI.PixmapCache
17
18
19 class E5LineEditSideWidget(QWidget):
16 """ 20 """
17 Class implementing the side widgets for the line edit class. 21 Class implementing the side widgets for the line edit class.
18 """ 22 """
19 sizeHintChanged = pyqtSignal() 23 sizeHintChanged = pyqtSignal()
20 24
56 60
57 self.setMinimumHeight(22) 61 self.setMinimumHeight(22)
58 62
59 self.__inactiveText = inactiveText 63 self.__inactiveText = inactiveText
60 64
61 self.__leftWidget = SideWidget(self) 65 self.__leftWidget = E5LineEditSideWidget(self)
62 self.__leftWidget.resize(0, 0) 66 self.__leftWidget.resize(0, 0)
63 self.__leftLayout = QHBoxLayout(self.__leftWidget) 67 self.__leftLayout = QHBoxLayout(self.__leftWidget)
64 self.__leftLayout.setContentsMargins(0, 0, 0, 0) 68 self.__leftLayout.setContentsMargins(0, 0, 0, 0)
65 if QApplication.isRightToLeft(): 69 if QApplication.isRightToLeft():
66 self.__leftLayout.setDirection(QBoxLayout.RightToLeft) 70 self.__leftLayout.setDirection(QBoxLayout.RightToLeft)
67 else: 71 else:
68 self.__leftLayout.setDirection(QBoxLayout.LeftToRight) 72 self.__leftLayout.setDirection(QBoxLayout.LeftToRight)
69 self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize) 73 self.__leftLayout.setSizeConstraint(QLayout.SetFixedSize)
70 74
71 self.__rightWidget = SideWidget(self) 75 self.__rightWidget = E5LineEditSideWidget(self)
72 self.__rightWidget.resize(0, 0) 76 self.__rightWidget.resize(0, 0)
73 self.__rightLayout = QHBoxLayout(self.__rightWidget) 77 self.__rightLayout = QHBoxLayout(self.__rightWidget)
74 self.__rightLayout.setContentsMargins(0, 0, 0, 0) 78 self.__rightLayout.setContentsMargins(0, 0, 0, 0)
75 if self.isRightToLeft(): 79 if self.isRightToLeft():
76 self.__rightLayout.setDirection(QBoxLayout.RightToLeft) 80 self.__rightLayout.setDirection(QBoxLayout.RightToLeft)
248 252
249 @param inactiveText text to be shown on inactivity (string) 253 @param inactiveText text to be shown on inactivity (string)
250 """ 254 """
251 self.__inactiveText = inactiveText 255 self.__inactiveText = inactiveText
252 self.update() 256 self.update()
257
258
259 class E5ClearableLineEdit(E5LineEdit):
260 """
261 Class implementing a line edit widget showing some inactive text and a clear button,
262 if it has some contents.
263 """
264 def __init__(self, parent=None, inactiveText="", side=E5LineEdit.RightSide):
265 """
266 Constructor
267
268 @param parent reference to the parent widget (QWidget)
269 @keyparam inactiveText text to be shown on inactivity (string)
270 @keyparam side side the clear button should be shown at (E5LineEdit.RightSide,
271 E5LineEdit.LeftSide)
272 """
273 assert side in [E5LineEdit.RightSide, E5LineEdit.LeftSide]
274
275 super().__init__(parent, inactiveText)
276
277 self.__clearButton = E5LineEditButton(self)
278 self.__clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png"))
279 self.addWidget(self.__clearButton, side)
280 self.__clearButton.setVisible(False)
281
282 self.__clearButton.clicked[()].connect(self.clear)
283 self.textChanged.connect(self.__textChanged)
284
285 def __textChanged(self, txt):
286 """
287 Private slot to handle changes of the text.
288
289 @param txt text (string)
290 """
291 self.__clearButton.setVisible(txt != "")

eric ide

mercurial