예제 #1
0
파일: dockwidget.py 프로젝트: gpa14/enki
    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)
예제 #2
0
    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)
예제 #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
    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
예제 #5
0
    def paintEvent(self, event):
        """Paint event."""
        qp = QPainter()
        qp.begin(self)

        # ---- get default style ----

        opt = QStyleOptionButton()
        self.initStyleOption(opt)

        # ---- scale icon to button size ----

        Rect = opt.rect

        h = Rect.height()
        w = Rect.width()
        iconSize = max(min(h, w) - 2 * self.pad, self.minSize)

        opt.iconSize = QSize(iconSize, iconSize)

        # ---- draw button ----

        self.style().drawControl(QStyle.CE_PushButton, opt, qp, self)

        qp.end()
예제 #6
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
예제 #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)