Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Brainstorm
  4. ability to apply stylesheet to individual items in QComboBox or QListView

ability to apply stylesheet to individual items in QComboBox or QListView

Scheduled Pinned Locked Moved Unsolved Brainstorm
2 Posts 2 Posters 1.0k Views
  • 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 FeldmanP Offline
    Phillip M FeldmanP Offline
    Phillip M Feldman
    wrote on last edited by
    #1

    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
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      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
      0

      • Login

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