def paintEvent(self, ev): size = self._icon_size if self._icon_size > 10 else self.iconSize().width() p = QPainter(self) opt = QStyleOptionToolButton() self.initStyleOption(opt) s = self.style() opt.iconSize = QSize(size, size) s.drawComplexControl(s.CC_ToolButton, opt, p, self)
def __init__(self, parent=None): super(ToolButton, self).__init__(parent) self._multiIcon = QImage() self._themeIcon = '' self._pressTimer = QTimer() self._menu = None # QMenu self._options = 0 self.setMinimumWidth(16) opt = QStyleOptionToolButton() self.initStyleOption(opt) self._pressTimer.setSingleShot(True) self._pressTimer.setInterval(QApplication.style().styleHint( QStyle.SH_ToolButton_PopupDelay, opt, self )) self._pressTimer.timeout.connect(self._showMenu)