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] Changing the color of a QListWidget

[SOLVED] Changing the color of a QListWidget

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 8.8k 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.
  • C Offline
    C Offline
    Chrisw01
    wrote on last edited by
    #1

    Hi,

    I'm trying to change the color(s) of the selected item from the default blue and light grey to a predefined rgb color and seem to be having a bit of a problem. I'm using the folowing code.
    

    @
    ...
    p.setColor(QPalette::Base, QColor(0,0,0)); // Black Background
    p.setColor(QPalette::Text, QColor(r, g, b)) // Color of text;
    p.setColor(QPalette::Highlight, QColor(r, g, b));
    setPalette(p);
    @

    The background gets set to black, the text to the proper color, but the bar is still blue focused and grey not focused. I would prefer to use the palette instead of style sheets if possible.

    Thanks in advance...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      ScottR
      wrote on last edited by
      #2

      The "documentation":http://qt-project.org/doc/qt-4.8/qwidget.html#palette-prop for setPalette says the palette may be ignored on certain platforms. It implies that stylesheets will work.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        As ScottR said selection style is actually very platform dependent. Eg. on Windows it doesn't use palette because it adds some highlights and gradients .

        You can override this in stylesheet, but it's good to keep all color management in one place, so an easy fix would be to force the ui to use palette for selection:
        @
        ui->listWidget->setStyleSheet("QListView::item:selected { background: palette(Highlight) }");
        @
        Then you can control the actual color via palette with all the other colors.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chrisw01
          wrote on last edited by
          #4

          Thanks for the replies, really appreciate them, the second one however does not work as well.

          Thanks

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chrisw01
            wrote on last edited by
            #5

            Hi guys,

            Thanks for all the help, I took a different approach to it and decided to utilize the style sheets while maintaining control over custom colors. Works like a champ..

            Thanks again for all your help.

            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