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. How to set QComboBox background color with QPalette?

How to set QComboBox background color with QPalette?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 3.4k 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.
  • T Offline
    T Offline
    Tapsa
    wrote on last edited by
    #1

    It seems that none of the colors in the palette of QComboBox are used to draw its background. Only the drop down triangle is changed to white with this code. (I have no entries yet in the boxes.)

    QPalette pal(palette());
    QBrush brush(Qt::white);
    pal.setBrush(QPalette::Window, brush);
    pal.setBrush(QPalette::Background, brush);
    pal.setBrush(QPalette::WindowText, brush);
    pal.setBrush(QPalette::Foreground, brush);
    pal.setBrush(QPalette::Base, brush);
    pal.setBrush(QPalette::AlternateBase, brush);
    pal.setBrush(QPalette::ToolTipBase, brush);
    pal.setBrush(QPalette::ToolTipText, brush);
    pal.setBrush(QPalette::Text, brush);
    pal.setBrush(QPalette::Button, brush);
    pal.setBrush(QPalette::ButtonText, brush);
    pal.setBrush(QPalette::BrightText, brush);
    pal.setBrush(QPalette::Base, brush);
    pal.setBrush(QPalette::Light, brush);
    pal.setBrush(QPalette::Midlight, brush);
    pal.setBrush(QPalette::Dark, brush);
    pal.setBrush(QPalette::Mid, brush);
    pal.setBrush(QPalette::Shadow, brush);
    pal.setBrush(QPalette::NoRole, brush);
    setPalette(pal);
    

    I tried to change the palette from designer too, but it appears that the background color of QComboBox is not defined in its palette, but determined elsewhere. How can I change the background color? If I use style sheet, QComboBox graphics reset to some really ugly look (since it has no default style sheet), but the background color changes.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Please try this
      QPalette palette = ui->combo->palette();
      palette.setColor(QPalette::Active, QPalette::Button, Qt::white);
      palette.setColor(QPalette::Inactive, QPalette::Button, Qt::white);
      ui->combo->setPalette(palette);

      Also, a note on style sheets.
      If u use a style sheet, its a all or nothing thing. (sadly)

      So when u set something, it will loose its images etc so
      to change it, you must change most of it.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        Tapsa
        wrote on last edited by
        #3

        I did that in the constructor of my sub classed QComboBox, but it changes nothing. Did you test if it works for you?

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You are right. In win 7 it changes nothing.
          Sorry.

          1 Reply Last reply
          1

          • Login

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