December 5, 2011

Asperamanca Asperamanca
Robot Herder
722 posts

Menubar uses colors not defined in QApplication::palette()

 

On Windows 7, the menu bar draws in colors I haven’t defined in QApplication::palette().

I am changing all the colors in the palette, yet, the menu bar background is drawn in two different colors.

This is the code I use to set the colors. I don’t think I missed anything as major as a menu background (and it does work on XP):

  1.     QPalette pal = QApplication::palette();
  2.  
  3.     setColorAndBrush(pal, QPalette::Window,
  4.                      QColor(50,50,50));
  5.     setColorAndBrush(pal, QPalette::WindowText,
  6.                      Qt::white);
  7.     setColorAndBrush(pal, QPalette::WindowText,
  8.                      QColor(159,159,159),
  9.                      QPalette::Disabled);
  10.     setColorAndBrush(pal, QPalette::Base,
  11.                      Qt::black);
  12.     setColorAndBrush(pal, QPalette::Text,
  13.                      Qt::white);
  14.     setColorAndBrush(pal, QPalette::AlternateBase,
  15.                      QColor(100,100,100));
  16.     setColorAndBrush(pal, QPalette::ToolTipBase,
  17.                      QColor(255, 255, 225));
  18.     setColorAndBrush(pal, QPalette::ToolTipText,
  19.                      Qt::black);
  20.     setColorAndBrush(pal, QPalette::Button, Qt::black);
  21.     setColorAndBrush(pal, QPalette::ButtonText,
  22.                      Qt::white);
  23.     setColorAndBrush(pal, QPalette::ButtonText,
  24.                      QColor(159,159,159),
  25.                      QPalette::Disabled);
  26.     setColorAndBrush(pal, QPalette::BrightText,
  27.                      Qt::white);
  28.  
  29.     setColorAndBrush(pal, QPalette::Light,
  30.                      QColor(120,120,120));
  31.     setColorAndBrush(pal, QPalette::Midlight,
  32.                      QColor(90,90,90));
  33.     setColorAndBrush(pal, QPalette::Mid,
  34.                      QColor(60,60,60));
  35.     setColorAndBrush(pal, QPalette::Dark,
  36.                      QColor(30,30,30));
  37.     setColorAndBrush(pal, QPalette::Shadow,
  38.                      Qt::black);
  39.  
  40.     setColorAndBrush(pal, QPalette::Highlight, QColor(40,40,70));
  41.     setColorAndBrush(pal, QPalette::HighlightedText, Qt::white);
  42.  
  43.     setColorAndBrush(pal, QPalette::Link, QColor(85,170,255));
  44.     setColorAndBrush(pal, QPalette::LinkVisited, QColor(170,100,240));
  45.  
  46.     QApplication::setPalette(pal);

NOTE: This is an application for an embedded device that is only run on Windows for testing purposes. Hence the rather strange style for a windows application.
Still, even for testing purposes, the menu items should be readable.

2 replies

December 5, 2011

Andre Andre
Robot Herder
6422 posts

As in the documentation [developer.qt.nokia.com]:

Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.

So, this behaviour is to be expected.

Note that while styles are free to ignore the palette, the build-in Qt styles will not ignore style sheets.

December 5, 2011

Asperamanca Asperamanca
Robot Herder
722 posts

Thanks, that seems to be the point I missed!

 
  ‹‹ How to save style before changing it?      Shaped toplevel Widgets ››

You must log in to post a reply. Not a member yet? Register here!