--- a/E5Gui/E5ToolButton.py Sun Feb 11 16:04:16 2018 +0100 +++ b/E5Gui/E5ToolButton.py Sun Feb 11 16:04:47 2018 +0100 @@ -11,7 +11,7 @@ from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QTimer, QSize from PyQt5.QtWidgets import QToolButton, QStyle, QStyleOptionToolButton, \ - QStyleOption, QApplication + QStyleOption, QApplication, QLabel class E5ToolButton(QToolButton): @@ -50,6 +50,12 @@ self.__menu = None self.__options = E5ToolButton.NoOptions + self.__badgeLabel = QLabel(self) + font = self.__badgeLabel.font() + font.setPixelSize(self.__badgeLabel.height() / 2.5) + self.__badgeLabel.setFont(font) + self.__badgeLabel.hide() + opt = QStyleOptionToolButton() self.initStyleOption(opt) @@ -251,3 +257,32 @@ return super(E5ToolButton, self).contextMenuEvent(evt) + + ################################################################## + ## Methods to handle the tool button badge + ################################################################## + + def setBadgeText(self, text): + """ + Public method to set the badge text. + + @param text badge text to be set + @type str + """ + if text: + self.__badgeLabel.setText(text) + self.__badgeLabel.resize(self.__badgeLabel.sizeHint()) + self.__badgeLabel.move(self.width() - self.__badgeLabel.width(), 0) + self.__badgeLabel.show() + else: + self.__badgeLabel.clear() + self.__badgeLabel.hide() + + def badgeText(self): + """ + Public method to get the badge text. + + @return badge text + @rtype str + """ + return self.__badgeLabel.text()