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
Пример #2
0
 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()
Пример #3
0
    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
Пример #4
0
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
Пример #5
0
 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
Пример #6
0
    def _draw_context_menu_button(self, painter, option, index):
        style = QStyleOptionButton()
        style.features = QStyleOptionButton.Flat
        style.rect = self._context_menu_button_rect(option, index)
        style.text = "☰"
        style.state = QStyle.State_Enabled

        painter.setPen(QColor("blue"))
        QApplication.style().drawControl(
            QStyle.CE_PushButton,
            style,
            painter
        )
Пример #7
0
    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)
Пример #8
0
    def paint(self, painter: QPainter, option: 'QStyleOptionViewItem', index: QModelIndex) -> None:
        widget = option.widget
        self.initStyleOption(option, index)
        style = QApplication.style() if widget is None else widget.style()
        style.drawControl(QStyle.CE_ItemViewItem, option, painter, widget)

        if not (option.state & QStyle.State_Editing):
            return
        btn_address = QStyleOptionButton()
        btn_address.features = QStyleOptionButton.DefaultButton
        btn_address.fontMetrics = option.fontMetrics
        btn_address.palette = option.palette
        btn_address.styleObject = option.styleObject
        btn_address.rect = QRect(option.rect.left() + option.rect.width() - option.rect.height(),
                                 option.rect.top(), option.rect.height(), option.rect.height())

        style.drawControl(QStyle.CE_PushButton, btn_address, painter, widget)