def paintEvent(self, event): """QToolBar.paintEvent reimplementation Draws buttons, dock icon and text """ rect = self._spacer.rect() painter = QPainter(self) transform = QTransform() transform.translate(self._spacer.pos().x(), self._spacer.pos().y()) painter.setTransform(transform) """ Not supported currently if self._dock.features() & QDockWidget.DockWidgetVerticalTitleBar : transform = QTransform() rect.setSize(QSize(rect.height(), rect.width())) transform.rotate(-90) transform.translate(-rect.width(), 0) painter.setTransform(transform) """ # icon / title optionB = QStyleOptionButton() optionB.initFrom(self._dock) optionB.rect = rect optionB.text = self._dock.windowTitle() optionB.iconSize = self.iconSize() optionB.icon = self._dock.windowIcon() self.style().drawControl(QStyle.CE_PushButtonLabel, optionB, painter, self._dock)
def paintEvent(self, event): self._initAnimate() painter = QStylePainter(self) painter.setRenderHint(QPainter.Antialiasing, True) painter.setRenderHint(QPainter.HighQualityAntialiasing, True) painter.setRenderHint(QPainter.SmoothPixmapTransform, True) painter.setBrush(QColor(self._bgcolor)) painter.setPen(QColor(self._bgcolor)) painter.drawEllipse(QRectF( (self.minimumWidth() - self._width) / 2, (self.minimumHeight() - self._height) / 2, self._width, self._height )) # 绘制本身的文字和图标 options = QStyleOptionButton() options.initFrom(self) size = options.rect.size() size.transpose() options.rect.setSize(size) options.features = QStyleOptionButton.Flat options.text = self.text() options.icon = self.icon() options.iconSize = self.iconSize() painter.drawControl(QStyle.CE_PushButton, options) event.accept()
def paintEvent(self, e): painter = QPainter(self) # Draw empty button (no label or icon). buttonStyle = QStyleOptionButton() self.initStyleOption(buttonStyle) buttonStyle.text = '' buttonStyle.icon = QIcon() buttonStyle.iconSize = QSize(-1, -1) self.style().drawControl(QStyle.CE_PushButton, buttonStyle, painter, self) # Get button label style. labelStyle = QStyleOptionButton() self.initStyleOption(labelStyle) labelStyle.rect = self.style().subElementRect(QStyle.SE_PushButtonContents, labelStyle, self) # Clip everything we paint to label area. painter.setClipRect(labelStyle.rect) painter.setClipping(True) # TODO painter.translate(-200, 0); # Has to happen after we set clipping. # Draw label (optionally with icon), similar to how Qt does it (src/widgets/styles/qcommonstyle.cpp in Qt 5.3). self.style().drawControl(QStyle.CE_PushButtonLabel, labelStyle, painter, self)
def getStyleOptions(self): options = QStyleOptionButton() options.initFrom(self) size = options.rect.size() if self.orientation == self.Vertical: size.transpose() options.rect.setSize(size) options.features = QStyleOptionButton.None_ if self.isFlat(): options.features |= QStyleOptionButton.Flat if self.menu(): options.features |= QStyleOptionButton.HasMenu if self.autoDefault() or self.isDefault(): options.features |= QStyleOptionButton.AutoDefaultButton if self.isDefault(): options.features |= QStyleOptionButton.DefaultButton if self.isDown() or (self.menu() and self.menu().isVisible()): options.state |= QStyle.State_Sunken if self.isChecked(): options.state |= QStyle.State_On if not self.isFlat() and not self.isDown(): options.state |= QStyle.State_Raised options.text = self.text() options.icon = self.icon() options.iconSize = self.iconSize() return options
def getSyleOptions(self) -> QStyleOptionButton: options = QStyleOptionButton() options.initFrom(self) size = options.rect.size() size.transpose() options.rect.setSize(size) try: options.features = QStyleOptionButton.None_ except AttributeError: # Allow for bug in PyQt 5.4 options.features = getattr(QStyleOptionButton, "None") if self.isFlat(): options.features |= QStyleOptionButton.Flat if self.menu(): options.features |= QStyleOptionButton.HasMenu if self.autoDefault() or self.isDefault(): options.features |= QStyleOptionButton.AutoDefaultButton if self.isDefault(): options.features |= QStyleOptionButton.DefaultButton if self.isDown() or (self.menu() and self.menu().isVisible()): options.state |= QStyle.State_Sunken if self.isChecked(): options.state |= QStyle.State_On if not self.isFlat() and not self.isDown(): options.state |= QStyle.State_Raised options.text = self.text() options.icon = self.icon() options.iconSize = self.iconSize() return options
def getSyleOptions(self): options = QStyleOptionButton() options.initFrom(self) size = options.rect.size() size.transpose() options.rect.setSize(size) options.features = QStyleOptionButton.DefaultButton options.text = self.text() options.icon = self.icon() options.iconSize = self.iconSize() return options
def getSyleOptions(self): """QPushButton的Options""" options = QStyleOptionButton() options.initFrom(self.clazz) size = options.rect.size() size.transpose() options.rect.setSize(size) options.features = QStyleOptionButton.DefaultButton options.text = self.clazz.text() options.icon = self.clazz.icon() options.iconSize = self.clazz.iconSize() return options
def paint(self, painter, option, index): if index.column() != 1: QStyledItemDelegate.paint(self, painter, option, index) return model: Any[FileSystemTreeModel | QAbstractItemModel] = index.model() node = model.getNode(index) if node.is_fetch_more: QStyledItemDelegate.paint(self, painter, option, index) return rect = option.rect # btn = QStyleOptionToolButton() # btn.rect = QRect(rect.left() + rect.width() - 30, # rect.top(), 30, rect.height()) # btn.text = '...' # btn.toolButtonStyle = Qt.ToolButtonIconOnly # btn.icon = COG_ICON # btn.iconSize = QSize(16, 16) # btn.features = QStyleOptionToolButton.Menu | \ # QStyleOptionToolButton.MenuButtonPopup | \ # QStyleOptionToolButton.HasMenu # btn.features = QStyleOptionToolButton.Menu # btn.state = QStyle.State_Enabled | \ # (QStyle.State_MouseOver # if option.state & QStyle.State_MouseOver # else QStyle.State_None) # btn.state = QStyle.State_Enabled # QApplication.style().drawComplexControl( # QStyle.CC_ToolButton, btn, painter) btn = QStyleOptionButton() btn.icon = COG_ICON btn.iconSize = QSize(16, 16) btn.features = QStyleOptionButton.Flat btn.features |= QStyleOptionButton.HasMenu btn.state = QStyle.State_Enabled btn.state |= (QStyle.State_MouseOver if option.state & QStyle.State_MouseOver else QStyle.State_Enabled) btn.state |= (QStyle.State_Selected if option.state & QStyle.State_Selected else QStyle.State_Enabled) btn.state |= (QStyle.State_Active if option.state & QStyle.State_Active else QStyle.State_Enabled) btn.rect = QRect(rect.left() + rect.width() - 30, rect.top(), 30, rect.height()) QApplication.style().drawControl(QStyle.CE_PushButton, btn, painter)