E5Gui/E5ToolButton.py

changeset 6134
cb0985e8da91
parent 6048
82ad8ec9548c
child 6645
ad476851d7e0
equal deleted inserted replaced
6133:eba07240fac1 6134:cb0985e8da91
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QTimer, QSize 12 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QTimer, QSize
13 from PyQt5.QtWidgets import QToolButton, QStyle, QStyleOptionToolButton, \ 13 from PyQt5.QtWidgets import QToolButton, QStyle, QStyleOptionToolButton, \
14 QStyleOption, QApplication 14 QStyleOption, QApplication, QLabel
15 15
16 16
17 class E5ToolButton(QToolButton): 17 class E5ToolButton(QToolButton):
18 """ 18 """
19 Class implementing a specialized tool button subclass. 19 Class implementing a specialized tool button subclass.
48 self.setMinimumWidth(16) 48 self.setMinimumWidth(16)
49 49
50 self.__menu = None 50 self.__menu = None
51 self.__options = E5ToolButton.NoOptions 51 self.__options = E5ToolButton.NoOptions
52 52
53 self.__badgeLabel = QLabel(self)
54 font = self.__badgeLabel.font()
55 font.setPixelSize(self.__badgeLabel.height() / 2.5)
56 self.__badgeLabel.setFont(font)
57 self.__badgeLabel.hide()
58
53 opt = QStyleOptionToolButton() 59 opt = QStyleOptionToolButton()
54 self.initStyleOption(opt) 60 self.initStyleOption(opt)
55 61
56 self.__pressTimer = QTimer() 62 self.__pressTimer = QTimer()
57 self.__pressTimer.setSingleShot(True) 63 self.__pressTimer.setSingleShot(True)
249 # block to prevent showing the context menu and the tool button menu 255 # block to prevent showing the context menu and the tool button menu
250 if self.__menu is not None: 256 if self.__menu is not None:
251 return 257 return
252 258
253 super(E5ToolButton, self).contextMenuEvent(evt) 259 super(E5ToolButton, self).contextMenuEvent(evt)
260
261 ##################################################################
262 ## Methods to handle the tool button badge
263 ##################################################################
264
265 def setBadgeText(self, text):
266 """
267 Public method to set the badge text.
268
269 @param text badge text to be set
270 @type str
271 """
272 if text:
273 self.__badgeLabel.setText(text)
274 self.__badgeLabel.resize(self.__badgeLabel.sizeHint())
275 self.__badgeLabel.move(self.width() - self.__badgeLabel.width(), 0)
276 self.__badgeLabel.show()
277 else:
278 self.__badgeLabel.clear()
279 self.__badgeLabel.hide()
280
281 def badgeText(self):
282 """
283 Public method to get the badge text.
284
285 @return badge text
286 @rtype str
287 """
288 return self.__badgeLabel.text()

eric ide

mercurial