Using multiple QStyledItemDelegate with stylesheets

后端 未结 1 1781
别那么骄傲
别那么骄傲 2021-02-13 20:59

I\'m creating a styled QTreeView using double-dispatch to resolve specific delegate for data items, which is working great. I subclassed the delegates from QStyledItemDelegate

相关标签:
1条回答
  • 2021-02-13 21:15

    Different styles can't be selected that way. The properties for selecting the style sheet rule are taken from a QWidget (a QTreeView in this case), not a delegate. The delegate is not a widget, and there isn't a widget representing individual items. Your example can show this by adding a print where the style is obtained from the widget:

    style = opt.widget.style()
    print opt.widget
    

    It will show that the widget for the style a QTreeView. Since the widget is the same for both delegates, it can't have a role setting that is two values.

    Even though the style sheet is written so that it looks like the role is associated with an item, the rule selection is like it was written as:

    QTreeView[role="title"]::item:selected
    
    0 讨论(0)
提交回复
热议问题