Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved ability to apply stylesheet to individual items in QComboBox or QListView

    Brainstorm
    2
    2
    853
    Loading More Posts
    • 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.
    • Phillip M Feldman
      Phillip M Feldman last edited by

      I was surprised and disappointed to discover that one cannot apply stylesheets to individual items in a QComboBox or QListView. One can separately set the background color, foreground (text) color, and the font size, but this is cumbersome and does not support the wide range of effects that is possible with stylesheets. Has anyone thought about adding this capability? Why does this ugly dichotomy exist?

      Dr. Phillip M. Feldman
      http://phillipmfeldman.org

      1 Reply Last reply Reply Quote 0
      • hskoglund
        hskoglund last edited by

        Hi, while I think you're correct about QComboBox, for QListView I think you can apply individual stylesheets to it. If you can use a QListWidget instead I have an example:

            for (int i = 0; (i < 10); ++i)
                ui->listWidget->addItem(new QListWidgetItem(""));
        
            QLabel* l1 = new QLabel("Item1",this);
            l1->setStyleSheet("* { color: #FF0000; }");
            ui->listWidget->setItemWidget(ui->listWidget->item(0),l1);
        
            QLabel* l2 = new QLabel("Item2",this);
            l2->setStyleSheet("* { color: #00FF00; }");
            ui->listWidget->setItemWidget(ui->listWidget->item(1),l2);
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post