E5Gui/E5LineEdit.py

changeset 1964
6a6a53f2d086
parent 1509
c0b5e693b0eb
child 2077
68a34718a0ce
equal deleted inserted replaced
1963:9c5b3235abf9 1964:6a6a53f2d086
5 5
6 """ 6 """
7 Module implementing specialized line edits. 7 Module implementing specialized line edits.
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent 10 from PyQt4.QtCore import pyqtSignal, Qt, QEvent, qVersion
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
15 class SideWidget(QWidget): 15 class SideWidget(QWidget):
54 """ 54 """
55 super().__init__(parent) 55 super().__init__(parent)
56 56
57 self.setMinimumHeight(22) 57 self.setMinimumHeight(22)
58 58
59 self.__inactiveText = inactiveText 59 if qVersion() < "4.7.0":
60 self.__inactiveText = inactiveText
61 else:
62 self.setPlaceholderText(inactiveText)
60 63
61 self.__leftWidget = SideWidget(self) 64 self.__leftWidget = SideWidget(self)
62 self.__leftWidget.resize(0, 0) 65 self.__leftWidget.resize(0, 0)
63 self.__leftLayout = QHBoxLayout(self.__leftWidget) 66 self.__leftLayout = QHBoxLayout(self.__leftWidget)
64 self.__leftLayout.setContentsMargins(0, 0, 0, 0) 67 self.__leftLayout.setContentsMargins(0, 0, 0, 0)
114 117
115 @param evt reference to the paint event (QPaintEvent) 118 @param evt reference to the paint event (QPaintEvent)
116 """ 119 """
117 super().paintEvent(evt) 120 super().paintEvent(evt)
118 121
119 if not self.text() and \ 122 if qVersion() < "4.7.0":
120 self.__inactiveText and \ 123 if not self.text() and \
121 not self.hasFocus(): 124 self.__inactiveText and \
122 panel = QStyleOptionFrameV2() 125 not self.hasFocus():
123 self.initStyleOption(panel) 126 panel = QStyleOptionFrameV2()
124 textRect = \ 127 self.initStyleOption(panel)
125 self.style().subElementRect(QStyle.SE_LineEditContents, panel, self) 128 textRect = \
126 textRect.adjust(2, 0, 0, 0) 129 self.style().subElementRect(QStyle.SE_LineEditContents, panel, self)
127 left = self.textMargin(self.LeftSide) 130 textRect.adjust(2, 0, 0, 0)
128 right = self.textMargin(self.RightSide) 131 left = self.textMargin(self.LeftSide)
129 textRect.adjust(left, 0, -right, 0) 132 right = self.textMargin(self.RightSide)
130 painter = QPainter(self) 133 textRect.adjust(left, 0, -right, 0)
131 painter.setPen(self.palette().brush(QPalette.Disabled, QPalette.Text).color()) 134 painter = QPainter(self)
132 painter.drawText( 135 painter.setPen(self.palette().brush(
133 textRect, Qt.AlignLeft | Qt.AlignVCenter, self.__inactiveText) 136 QPalette.Disabled, QPalette.Text).color())
137 painter.drawText(
138 textRect, Qt.AlignLeft | Qt.AlignVCenter, self.__inactiveText)
134 139
135 def __updateSideWidgetLocations(self): 140 def __updateSideWidgetLocations(self):
136 """ 141 """
137 Private method to update the side widget locations. 142 Private method to update the side widget locations.
138 """ 143 """
238 """ 243 """
239 Public method to get the inactive text. 244 Public method to get the inactive text.
240 245
241 return inactive text (string) 246 return inactive text (string)
242 """ 247 """
243 return self.__inactiveText 248 if qVersion() < "4.7.0":
249 return self.__inactiveText
250 else:
251 return self.placeholderText()
244 252
245 def setInactiveText(self, inactiveText): 253 def setInactiveText(self, inactiveText):
246 """ 254 """
247 Public method to set the inactive text. 255 Public method to set the inactive text.
248 256
249 @param inactiveText text to be shown on inactivity (string) 257 @param inactiveText text to be shown on inactivity (string)
250 """ 258 """
251 self.__inactiveText = inactiveText 259 if qVersion() < "4.7.0":
252 self.update() 260 self.__inactiveText = inactiveText
261 self.update()
262 else:
263 self.setPlaceholderText(inactiveText)

eric ide

mercurial