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. QPalette.HighlightedText not returning accurate value?
Forum Updated to NodeBB v4.3 + New Features

QPalette.HighlightedText not returning accurate value?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 297 Views 2 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    I am trying to get the color that will contrast well with QPalette.Highlight, which is supposed to be QPalette.HighlightedText. However, the value returned in both the app or widget palette is not the value used in painting (Qt-5.13.1).

    Surely there is something I am doing wrong?

    app = QApplication(sys.argv)
    w = QListWidget()
    w.addItem('Here')
    w.addItem('You')
    w.addItem('Are')
    w.show()
    
    palette = w.palette()
    SELECTED_TEXT_COLOR = palette.color(QPalette.HighlightedText)
    print('QPalette.HighlightedText:', SELECTED_TEXT_COLOR.name())
    
    app.exec()
    

    Screen Shot 2019-10-18 at 9.09.23 AM.png

    https://alaskafamilysystems.com/

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

      Hi
      Nope, you are not doing anything wrong. :)
      It seems to depend a bit on the Widget in Question, the QStyle used and platform if the palette is used for the actual drawing.

      So more often stylesheets work better.

      When i want to use palette, i normally test it first

      QPalette p = ui->listWidget->palette();
          for (int cr = QPalette::ColorRole::WindowText; cr < QPalette::ColorRole::PlaceholderText; ++cr) {
              p.setColor( QPalette::ColorRole(cr), Qt::red);
          }
          ui->listWidget->setPalette(p);
      

      This changes all colors so its easy to see if it will work. ( on that platform)

      so here on ListWidget ( windows platform) does seems to use it
      alt text

      However, i can also see some effect is added to the selected drawing. as else it would not be visisble.

      Also as a note. you are taking the system palette.
      Also test the Widgets one (just to be sure)
      SELECTED_TEXT_COLOR = w.palette.color(QPalette.HighlightedText)

      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