样式在使用QItemDelegate时无法生效

4
我有一个QTreeview,我使用了这个样式表。
QTreeView#treeView::item:selected:active
{
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);
}
QTreeView#treeView::item:hover
{
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #e7effd, stop:1 #cbdaf1);
    border: 1px solid #bfcde4;
}
QTreeView#treeView::item:has-children
{
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #cccccc, stop:1 #aaaaaa);
    border: 1px solid #777777;
    border-left: 0;
    border-right: 0;
    font-weight: bold;
}

它的工作很好。但是当我使用

self.treeView.setItemDelegate(GenericDelegate())

以下是GenericDelegate定义的内容

class GenericDelegate(QItemDelegate):

    def _init_(self, parent=None):
        super(GenericDelegate, self)._init_(parent)

    def createEditor(self, parent, option, index): 
        if index.row()==1:
            cb = QtGui.QComboBox(parent)
            cb.addItems('A')
            cb.addItems('B')
            return cb

我的样式不再起作用了!
我是做错了什么吗?

1个回答

4

我应该使用

QStyledItemDelegate

而不是

QItemDelegate 

现在它可以工作了!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接