[Qt-interest] Where does QPalette::Disabled Get Set Up?

Jake Colman colman at ppllc.com
Tue Oct 19 00:39:28 CEST 2010


This question is not as obvious as it sounds.

I'm porting from Qt3 to Qt4.  The right-click menu on a QLineEdit
displays disabled items.  In Qt4 the text of a disabled item is dashed,
not solid.  The disabled item's background differs from the menu
background.  I'm trying to see where this is done so that I can override
and have it look the way it did in Qt3.

The code ported from Qt3 does the following:

  QDesktopWidget* Desktop = QApplication::desktop();
  QColorGroup ActiveColors = Desktop->colorGroup();

  QColor::setAllowX11ColorNames( true );  // needed for Qt4

  ActiveColors.setColor( QColorGroup::Background,      QColor("lightgrey") );
  ActiveColors.setColor( QColorGroup::Foreground,      QColor("black") );
  ActiveColors.setColor( QColorGroup::Base,            QColor("linen") );
  ActiveColors.setColor( QColorGroup::Text,            QColor("black") );
  ActiveColors.setColor( QColorGroup::Button,          QColor("lightgrey") );
  ActiveColors.setColor( QColorGroup::ButtonText,      QColor("black") );
  ActiveColors.setColor( QColorGroup::Highlight,       QColor("grey76") );
  ActiveColors.setColor( QColorGroup::HighlightedText, QColor("black") );

  QPalette P = QApplication::palette();
  P.setActive( ActiveColors );
  P.setInactive( ActiveColors );
  QApplication::setPalette(P);

This displays disabled items with a foreground of light grey and did not
change the text's background.  I'm having trouble getting the same
result in Qt4 but I cannot find where in the Qt4 source code this is
getting initialized.

I found that with Qt4 I also have to specify the Disabled ColorRole in
order to get something that remotely resembled Qt3 colors (I don't know
why I got away without this in Qt3).  I added the following (based on
Qt3 defaults from their source code):

  QColor standardLightGray( 192, 192, 192 );
  QColor light( 255, 255, 255 );
  QColor dark( standardLightGray.dark( 150 ) );
  QColorGroup DisabledColors( Qt::darkGray, standardLightGray,
                              light, dark, Qt::gray,
                              Qt::darkGray, ActiveColors.background() );

And, of course, added a call to:

  P.setDisabled( DisabledColors );

This does not, however, give me the solid text, etc, that I'm looking
for.

Any help out there?

Thanks.

...Jake


-- 
Jake Colman | Director, Software Development
Principia Partners LLC
101 West Elm Street | Conshohocken | PA 19428 | +1 (610) 755 9770
t: +1 (610) 755 9786 | c: +1 (610) 348 2788 | f: +1 (201) 221 8929
e: colman at ppllc.com | w: www.principiapartners.com
Credit technology innovation awards winner 2008 and 2009




More information about the Qt-interest-old mailing list