def paint(self, painter: QPainter, option: QStyleOptionViewItem, model_index: QModelIndex): """ Args: painter: Description option: Description model_index: Description """ # row = model_index.row() column = model_index.column() if column == 0: # Part Name option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) if column == 1: # Visibility value = model_index.model().data(model_index, Qt.EditRole) data_type = type(value) if data_type is str: # print("val", value) if COLOR_PATTERN.search(value): # print("found color") element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionViewItem() styleoption.palette.setBrush(QPalette.Button, getBrushObj(value)) styleoption.rect = QRect(option.rect) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) elif data_type is int: option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) elif data_type is float: option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) elif data_type is bool: element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionButton() styleoption.rect = QRect(option.rect) checked = value styleoption.state |= QStyle.State_On if checked else QStyle.State_Off styleoption.palette.setBrush(QPalette.Button, Qt.white) styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) if checked: element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) else: QStyledItemDelegate.paint(self, painter, option, model_index)
def paint(self, painter: QPainter, option: QStyleOptionViewItem, model_index: QModelIndex): """ Args: painter: Description option: Description model_index: Description """ # row = model_index.row() column = model_index.column() if column == 0: # Part Name option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) if column == 1: # Visibility value = model_index.model().data(model_index, Qt.EditRole) data_type = type(value) if data_type is str: # print("val", value) if COLOR_PATTERN.search(value): # print("found color") element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionViewItem() styleoption.palette.setBrush(QPalette.Button, getBrushObj(value)) styleoption.rect = QRect(option.rect) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) elif data_type is int: option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) elif data_type is float: option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) elif data_type is bool: element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionButton() styleoption.rect = QRect(option.rect) checked = value styleoption.state |= QStyle.State_On if checked else QStyle.State_Off styleoption.palette.setBrush(QPalette.Button, Qt.white) styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) if checked: element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) else: QStyledItemDelegate.paint(self, painter, option, model_index)
def paint(self, painter: QPainter, option: QStyleOptionViewItem, model_index: QModelIndex): column = model_index.column() new_rect = QRect(option.rect) if column == NAME_COL: # Part Name option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) if column == LOCKED_COL: # Visibility element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionButton() styleoption.rect = new_rect checked = model_index.model().data(model_index, Qt.EditRole) styleoption.state |= QStyle.State_On if checked else QStyle.State_Off # make the check box look a little more active by changing the pallete styleoption.palette.setBrush(QPalette.Button, Qt.white) styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) if checked: # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) # _QCOMMONSTYLE.drawItemText(painter, new_rect, Qt.AlignCenter, styleoption.palette, True, 'L') icon = QPixmap(":/outlinericons/lock") _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon) if column == VISIBLE_COL: # Visibility element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionButton() styleoption.rect = new_rect checked = model_index.model().data(model_index, Qt.EditRole) styleoption.state |= QStyle.State_On if checked else QStyle.State_Off # make the check box look a little more active by changing the pallete styleoption.palette.setBrush(QPalette.Button, Qt.white) styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) if checked: # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) icon = QPixmap(":/outlinericons/eye") _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon) elif column == COLOR_COL: # Color # Alternate way to get color # outline_tw = self.parent() # item = outline_tw.itemFromIndex(model_index) # color = item.getColor() # print("COLOR_COL", item) color = model_index.model().data(model_index, Qt.EditRole) element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionViewItem() brush = getBrushObj(color) styleoption.palette.setBrush(QPalette.Button, brush) styleoption.rect = new_rect _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) else: QStyledItemDelegate.paint(self, painter, option, model_index)
def paint(self, painter: QPainter, option: QStyleOptionViewItem, model_index: QModelIndex): column = model_index.column() new_rect = QRect(option.rect) if column == NAME_COL: # Part Name option.displayAlignment = Qt.AlignVCenter QStyledItemDelegate.paint(self, painter, option, model_index) if column == LOCKED_COL: # Visibility element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionButton() styleoption.rect = new_rect checked = model_index.model().data(model_index, Qt.EditRole) styleoption.state |= QStyle.State_On if checked else QStyle.State_Off # make the check box look a little more active by changing the pallete styleoption.palette.setBrush(QPalette.Button, Qt.white) styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) if checked: # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) # _QCOMMONSTYLE.drawItemText(painter, new_rect, Qt.AlignCenter, styleoption.palette, True, 'L') icon = QPixmap(":/outlinericons/lock") _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon) if column == VISIBLE_COL: # Visibility element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionButton() styleoption.rect = new_rect checked = model_index.model().data(model_index, Qt.EditRole) styleoption.state |= QStyle.State_On if checked else QStyle.State_Off # make the check box look a little more active by changing the pallete styleoption.palette.setBrush(QPalette.Button, Qt.white) styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black) _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) if checked: # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) icon = QPixmap(":/outlinericons/eye") _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon) elif column == COLOR_COL: # Color # Alternate way to get color # outline_tw = self.parent() # item = outline_tw.itemFromIndex(model_index) # color = item.getColor() # print("COLOR_COL", item) color = model_index.model().data(model_index, Qt.EditRole) element = _QCOMMONSTYLE.PE_IndicatorCheckBox styleoption = QStyleOptionViewItem() brush = getBrushObj(color) styleoption.palette.setBrush(QPalette.Button, brush) styleoption.rect = new_rect _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter) else: QStyledItemDelegate.paint(self, painter, option, model_index)