def paint(self,painter,option,index):
		model=index.model()
		option.state &= QStyle.State_Enabled ^ QStyle.State_Selected
		if model.parent(index).isValid():
			option.rect.setLeft(0)
			super(Delegate,self).paint(painter,option,index)
		else:
			i=9
			RECT = option.rect
			button = QStyleOptionButton()
			button.rect = RECT
			button.state = option.state
			button.state &= QStyle.State_HasFocus
			button.state |= QStyle.State_Raised
			button.features = QStyleOptionButton.None
			self._parent.style().drawControl(QStyle.CE_PushButton,button,painter,self._parent)
			branch = QStyleOption()
			branch.rect = QRect(RECT.left() + i/2, RECT.top() + (RECT.height() - i)/2, i, i)
			branch.palette = option.palette
			branch.state = QStyle.State_Children
			if self._parent.isExpanded(index):
				branch.state |= QStyle.State_Open
			self._parent.style().drawPrimitive(QStyle.PE_IndicatorBranch, branch, painter,self._parent);
			textrect = QRect(RECT.left() + i * 2, RECT.top(), RECT.width() - ((5*i)/2), RECT.height());
			#text = elidedText(option.fontMetrics, textrect.width(), Qt.ElideMiddle, model.data(index, Qt.DisplayRole).toString())
			text = model.data(index, Qt.DisplayRole).toString()
			self._parent.style().drawItemText(painter,textrect,Qt.AlignCenter,option.palette,self._parent.isEnabled(),text)
Beispiel #2
0
 def paintEvent(self, event: QPaintEvent):
     """
     Overrides QWidget.paintEvent().
     """
     painter = QPainter(self)
     option = QStyleOption()
     option.rect = self.rect()
     option.state = QStyle.State_Horizontal
     self.style().drawControl(QStyle.CE_ToolBar, option, painter, self)
Beispiel #3
0
 def paintEvent(self, event: QPaintEvent):
     """
     Overrides QWidget.paintEvent().
     """
     painter = QPainter(self)
     option = QStyleOption()
     option.rect = self.rect()
     option.state = QStyle.State_Horizontal
     option.palette = self.palette()
     self.style().drawPrimitive(QStyle.PE_IndicatorToolBarSeparator, option, painter, self)
Beispiel #4
0
    def paint(self, painter, option, index):
        """ Draw a button-style on root items """
        model = index.model()
        assert model


        if not model.parent(index).isValid():
            # this is a top-level item.
            buttonOption = QStyleOptionButton()

            buttonOption.state = option.state
            buttonOption.state &= ~QStyle.State_HasFocus

            buttonOption.rect = option.rect
            buttonOption.palette = option.palette
            buttonOption.features = QStyleOptionButton.None

            self.m_view.style().drawControl(QStyle.CE_PushButton, buttonOption, painter, self.m_view)

            branchOption = QStyleOption()
            i = 15  ### hardcoded in qcommonstyle.cpp
            r = option.rect
            branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i)
            branchOption.palette = option.palette
#            branchOption.state = QStyle.State_Children

            if self.m_view.isExpanded(index):
                branchOption.state |= QStyle.State_Open

            self.m_view.style().drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, painter, self.m_view)

            # draw text
            textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height())
            text = self.elidedText(option.fontMetrics, textrect.width(), Qt.ElideMiddle,
                              model.data(index, Qt.DisplayRole).toString())
            self.m_view.style().drawItemText(painter, textrect,Qt.AlignLeft|Qt.AlignVCenter,
                                             option.palette, self.m_view.isEnabled(), text)

            icon_variant = index.data(Qt.DecorationRole)
            icon = QIcon(icon_variant)
            self.m_view.style().drawItemPixmap(
                                               painter, option.rect,
                                               Qt.AlignLeft,
                                               icon.pixmap(icon.actualSize(QSize(20 ,20)))
                                               )

        else:
            QItemDelegate.paint(self, painter, option, index)