[Qt-interest] palette behaving in a strange manner.

Pritam Ghanghas pritam_ghanghas at infosys.com
Fri Mar 18 16:57:44 CET 2011


Hi

I am trying to set black color for QPalette::HighlightedText. and
setting a gradient for QPalette::Highlight. As soon as I set black for
HighlightedText, the Highlight gradient is drawn as black in listview.

The behaviour is correct only for a few color values of HighligtedText.

Here is a self contained example:

#include <QtGui>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QPalette pal = app.palette();

    pal.setCurrentColorGroup(QPalette::Normal);
    QLinearGradient hiGradient(0.5, 0, 0.5, 1);
    hiGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
    hiGradient.setColorAt(0, QColor("#36d3ff"));
    hiGradient.setColorAt(1, QColor("#048dad"));
    pal.setBrush(QPalette::Highlight, QBrush(hiGradient));
    pal.setColor(QPalette::HighlightedText, Qt::black);

    app.setPalette(pal);

    app.setStyle(new QCleanlooksStyle);

    QStringList stringList;
    stringList<<"a"<<"b"<<"c";

    QStringListModel model(stringList);

    QListView view;
    view.setModel(&model);
    view.show();

    return app.exec();
}

change the HighlightedText color to Qt::white or yellow it will work
fine. Change it to red or black it wont. There are other colors also for
which it works or doesn't work. I am unable to understand how it is
deciding? I tried manually getting the highlight brush and its right. 
So there is no corruption in palette.


-- 
Thanks,
Pritam




**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely 
for the use of the addressee(s). If you are not the intended recipient, please 
notify the sender by e-mail and delete the original message. Further, you are not 
to copy, disclose, or distribute this e-mail or its contents to any other person and 
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken 
every reasonable precaution to minimize this risk, but is not liable for any damage 
you may sustain as a result of any virus in this e-mail. You should carry out your 
own virus checks before opening the e-mail or attachment. Infosys reserves the 
right to monitor and review the content of all messages sent to or from this e-mail 
address. Messages sent to or from this e-mail address may be stored on the 
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***



More information about the Qt-interest-old mailing list