Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Style not working with QItemDelegate
Forum Updated to NodeBB v4.3 + New Features

[Solved] Style not working with QItemDelegate

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrbm
    wrote on last edited by
    #1

    I have a QTreeview and I used this stylesheet

    @ QTreeView::item:selected:active
    {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc);
    }
    QTreeView::item:hover
    {
    background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #e7effd, stop:1 #cbdaf1);
    border: 1px solid #bfcde4;
    }
    QTreeView::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;
    }@
    It works fine. But wen I use

    @ self.treeView.setItemDelegate(GenericDelegate())@

    Where GenericDelegate is defined as bellow

    @ 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@
    

    My style doesn't work any more!
    I am doing something wrong?

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Try inheriting from QStyledItemDelegate.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrbm
        wrote on last edited by
        #3

        Thanks.
        It works

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved