def paint(self, painter, option, index): # If we are looking at a method then draw a button # http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview?p=128623#post128623 if not hasattr(self, "blue_button"): self.blue_button = QPushButton() self.blue_button.setStyleSheet("color: rgb(0, 0, 196)") if index.isValid() and \ isinstance(index.internalPointer().data, Method): item = index.internalPointer() opt = QStyleOptionButton() style = QApplication.style() # If method is running, draw sunken if item.argvalue: opt.state |= QStyle.State_Enabled opt.state |= QStyle.State_Sunken # if method is allowed, draw blue elif self.method_allowed(item): opt.state |= QStyle.State_Enabled style = self.blue_button.style() # if we are hovering, draw highlight if option.state & QStyle.State_MouseOver: opt.state |= QStyle.State_MouseOver opt.rect = option.rect opt.text = index.internalPointer().name style.drawControl(QStyle.CE_PushButton, opt, painter, self.blue_button) else: if option.state & QStyle.State_Selected: # Don't show delegates as highlighted option.state = option.state ^ QStyle.State_Selected QStyledItemDelegate.paint(self, painter, option, index)
def paint(self, painter, option, index): # If we are looking at a method then draw a button # http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview?p=128623#post128623 if self.is_method_button(index): item = index.internalPointer() opt = QStyleOptionButton() style = QApplication.style() # If method is running, draw sunken if item.get_state() == item.RUNNING: opt.state |= QStyle.State_Enabled opt.state |= QStyle.State_Sunken # if method is allowed, draw blue elif item.get_writeable(): opt.state |= QStyle.State_Enabled # if we are hovering, draw highlight if option.state & QStyle.State_MouseOver: opt.state |= QStyle.State_MouseOver opt.rect = option.rect opt.text = item.get_label() style.drawControl(QStyle.CE_PushButton, opt, painter, QPushButton()) else: if option.state & QStyle.State_Selected: # Don't show delegates as highlighted option.state = option.state ^ QStyle.State_Selected QStyledItemDelegate.paint(self, painter, option, index)