def paint(self, painter, option, index): """Re-implemented paint method""" item = index.internalPointer() col = index.column() if not item.parent and (col == 3 or col == 4): s = QStyleOptionButton() checkbox_rect = QApplication.style(). \ subElementRect(QStyle.SE_CheckBoxIndicator, option) s.rect = option.rect center_offset = s.rect.width() / 2 - checkbox_rect.width() / 2 s.rect.adjust(center_offset, 0, 0, 0) if col == 3: if not item.doing_transaction(): s.state = QStyle.State_Enabled if item.logging_started(): s.state |= QStyle.State_On if col == 4: s.state = QStyle.State_Enabled if item.writing_to_file(): s.state |= QStyle.State_On QApplication.style().drawControl( QStyle.CE_CheckBox, s, painter) else: super(CheckboxDelegate, self).paint(painter, option, index)
def paint(self, painter, option, index): """Re-implemented paint method""" item = index.internalPointer() col = index.column() if not item.parent and (col == 3 or col == 4): s = QStyleOptionButton() checkbox_rect = QApplication.style(). \ subElementRect(QStyle.SE_CheckBoxIndicator, option) s.rect = option.rect center_offset = s.rect.width() / 2 - checkbox_rect.width() / 2 s.rect.adjust(center_offset, 0, 0, 0) if col == 3: if not item.doing_transaction(): s.state = QStyle.State_Enabled if item.logging_started(): s.state |= QStyle.State_On if col == 4: s.state = QStyle.State_Enabled if item.writing_to_file(): s.state |= QStyle.State_On QApplication.style().drawControl(QStyle.CE_CheckBox, s, painter) else: super(CheckboxDelegate, self).paint(painter, option, index)
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)
def paintCheckBoxColumn(self, painter, option, index): opt = QStyleOptionViewItemV4(option) buttonStyle = QStyleOptionButton() buttonStyle.state = QStyle.State_On if index.model().data(index, Qt.CheckStateRole) == QVariant(Qt.Checked) else QStyle.State_Off if option.state & QStyle.State_MouseOver or option.state & QStyle.State_HasFocus: buttonStyle.state |= QStyle.State_HasFocus buttonStyle.rect = opt.rect.adjusted(4, -opt.rect.height() + ROW_HEIGHT, 0, 0) PackageDelegate.AppStyle().drawControl(QStyle.CE_CheckBox, buttonStyle, painter, None)
def paintCheckBoxColumn(self, painter, option, index): opt = QStyleOptionViewItemV4(option) buttonStyle = QStyleOptionButton() buttonStyle.state = QStyle.State_On if index.model().data(index, Qt.CheckStateRole) == QVariant(Qt.Checked) else QStyle.State_Off if option.state & QStyle.State_MouseOver or option.state & QStyle.State_HasFocus: buttonStyle.state |= QStyle.State_HasFocus buttonStyle.rect = opt.rect.adjusted(4, -opt.rect.height() + ROW_HEIGHT, 0, 0) PackageDelegate.AppStyle().drawControl(QStyle.CE_CheckBox, buttonStyle, painter, None)
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)
def paint(self, painter, option, index): painter.save() if index.isValid(): style = self.parent().style() styleOption = QStyleOptionViewItemV4(option) node = index.internalPointer() val = index.model().data(index).toPyObject() if node.typeInfo == 'CODE': if node.valueFormat == 'percent': text = '%.2f %% ' % (val * 100) elif node.valueFormat == 'integer': text = '%d ' % val else: text = '%.2f ' % val styleOption.text = text styleOption.displayAlignment = Qt.AlignRight style.drawControl(QStyle.CE_ItemViewItem, styleOption, painter) elif node.typeInfo == 'BAREME' and index.column() == 2: styleOption = QStyleOptionButton() styleOption.rect = option.rect styleOption.text = QString('Editer') styleOption.textVisible = True styleOption.state = styleOption.state | QStyle.State_Enabled style.drawControl(QStyle.CE_PushButton, styleOption, painter) else: QStyledItemDelegate.paint(self, painter, styleOption, index) else: QStyledItemDelegate.paint(painter, option, index) painter.restore()
def paint(self, painter, option, index): painter.save() if index.isValid(): style = self.parent().style() styleOption = QStyleOptionViewItemV4(option) node = index.internalPointer() val = index.model().data(index).toPyObject() if node.typeInfo == 'CODE': if node.valueFormat == 'percent': text = '%.2f %% ' % (val*100) elif node.valueFormat == 'integer': text = '%d ' % val else: text = '%.2f ' % val styleOption.text = text styleOption.displayAlignment = Qt.AlignRight style.drawControl(QStyle.CE_ItemViewItem, styleOption, painter) elif node.typeInfo == 'BAREME' and index.column()==2: styleOption = QStyleOptionButton() styleOption.rect = option.rect styleOption.text = QString('Editer') styleOption.textVisible = True styleOption.state = styleOption.state | QStyle.State_Enabled style.drawControl(QStyle.CE_PushButton, styleOption, painter) else: QStyledItemDelegate.paint(self, painter, styleOption, index) else: QStyledItemDelegate.paint(painter, option, index) painter.restore()
def paint(self, painter, option, index): self.initStyleOption(option, index) if hasattr(option, "checkState"): if option.checkState == Qt.Unchecked: option.checkState = Qt.PartiallyChecked elif option.checkState == Qt.PartiallyChecked: option.checkState = Qt.Unchecked elif option.checkState == Qt.Checked: option.font = QFont(option.font) option.font.setStrikeOut(True) # ref: qt4-x11-4.6.2/src/gui/styles/qcommonstyle.cpp painter.save() painter.setClipRect(option.rect) # QApplication.style().drawControl( # QStyle.CE_ItemViewItem, option, painter, # getattr(option, "widget", None)) style = QApplication.style() widget = getattr(option, "widget", None) # log.debug("widget: %r style: %r" % (widget, style.metaObject().className())) style.drawPrimitive( QStyle.PE_PanelItemViewItem, option, painter, widget) if option.checkState == Qt.Checked: painter.setOpacity(0.3) text_rect = style.subElementRect( QStyle.SE_ItemViewItemText, option, widget) item_text = option.fontMetrics.elidedText( option.text, option.textElideMode, text_rect.width()) painter.setFont(option.font) style.drawItemText(painter, text_rect, option.displayAlignment, option.palette, True, item_text, QPalette.Text) check_rect = style.subElementRect( QStyle.SE_ItemViewItemCheckIndicator, option, widget) if option.checkState == Qt.PartiallyChecked: brush = option.palette.brush(QPalette.Base) painter.fillRect(check_rect, brush) bullet_rect = QRect(check_rect) if bullet_rect.width() > BULLET_SIZE: bullet_rect.setLeft( bullet_rect.left() + (bullet_rect.width() - BULLET_SIZE) / 2) bullet_rect.setWidth(BULLET_SIZE) if bullet_rect.height() > BULLET_SIZE: bullet_rect.setTop( bullet_rect.top() + (bullet_rect.height() - BULLET_SIZE) / 2) bullet_rect.setHeight(BULLET_SIZE) painter.setPen(QPen(option.palette.color(QPalette.Text))) painter.setBrush(option.palette.brush(QPalette.Text)) painter.drawEllipse(bullet_rect) else: check_opt = QStyleOptionButton() check_opt.rect = check_rect check_opt.state = option.state & ~QStyle.State_HasFocus if option.checkState == Qt.Checked: check_opt.state |= QStyle.State_On else: check_opt.state |= QStyle.State_Off style.drawPrimitive( QStyle.PE_IndicatorItemViewItemCheck, check_opt, painter, widget) painter.restore()