Question

I've created a Qt application using a slightly modified version of the 'cleanlooks' style. I've tried setting the WindowText with the following code but the change doesn't stick. when I open the application it opens in the background with the correct text color, when I click the application and bring it to the foreground the text reverts to black and I cant work out why. does anybody know why this may be or how I should be setting the window text?

#include <QtGui/QApplication>
#include <QtGui/QPalette>
#include <QtGui/QColor>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QPalette p;

    p.setBrush(QPalette::WindowText, QColor(255,0,0));

    a.setStyle("cleanlooks");
    a.setPalette(p);

    MainWindow w;
    w.show();

    return a.exec();
}

I'm using OSX 10.9 and Qt 4.8.6


Update 1

I tested the code on a windows 7 Machine running Qt 4.8.5 built from source and this problem did not occur. I't seems to be a problem with either MacOS 10.9 or Qt 4.8.6

Was it helpful?

Solution

I think that your answer is already reported (and confirmed) as a QT bug (QTBUG-32067).

While we have never really supported custom palette roles for most of QMacStyle I think we should allow setting a custom palette on it even if it breaks for some cases. Jens comment on QTBUG-32067

OTHER TIPS

See documentation notes of QApplication::setpalette.

Note: 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 the Windows XP, Windows Vista, and Mac OS X styles.

So you can can check this by running application with different style, by starting your application from shell like this:

applicationToRun -style=windows

Or by using other styles, docs says: motif, windows and platinum, but this depends on installed Qt and its plugins.


Edit: ups I didn't noticed that you are setting style by code. Anyway verify that style you are enforcing is supported by Qt on current machine, check if a.setStyle("cleanlooks"); returns a valid style (on errors it returns null). I would try all styles (list available form QStyleFactory::keys()).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top