PDA

View Full Version : QPalette works differently on windows and linux



babu198649
6th March 2008, 06:33
hi
i want to change color of push button .

the does this in linux but in windows it does not work .


#include <QtGui>

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

QPushButton b;
b.show();

QPalette palette;
QBrush brushg(QColor(0, 255, 0, 255));//green
palette.setBrush(QPalette::Active, QPalette::Button, brushg);
b.setPalette(palette);

return a.exec();
}


the above program displays a pushbutton in green color in linux, but the same program after compiling in windows and running the color of pushbutton is not green in color.

the same is with the designer. i can change the color of pushbutton using designer in linux but in windows it does not work.

jpn
6th March 2008, 06:58
Yes, it doesn't work on WinXP because QWindowsXpStyle uses native theming engine. It wouldn't work on Mac either.

Next time, please search the forums before starting new threads. This question has been asked and answered (too) many times, last time yesterday. There's even a FAQ entry: How to change the colour of a button or any other Qt widget? (http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_button_colo r)

babu198649
6th March 2008, 07:25
thanks for the link jpn.

in the link the code sets pushbutton to red color.

button->setStyleSheet("color: #0000dd; background-color: red;");

but even if we use

button->setStyleSheet("background-color: red;");

this we get the same ,then what does color: #0000dd signify and do we really need it. i have gone through the docs(The Style Sheet Syntax) and i have not found any thing like this.

jpn
6th March 2008, 07:27
i have gone through the docs(The Style Sheet Syntax) and i have not found any thing like this.
Really? It's all explained in the list of stylable properties: http://doc.trolltech.com/4.3/stylesheet-reference.html#color-prop