View Full Version : QPushbutton background color
omega36
30th October 2008, 13:01
Hello to all,
I wish to color the background of a button with RGB,
ideas?
Thank you
spirit
30th October 2008, 13:09
you can use style sheets (http://doc.trolltech.com/4.4/stylesheet-examples.html#customizing-qpushbutton) or QPalette
pastor
30th October 2008, 13:12
Hello!
Try following as example:
QPalette p = pb->palette();
p.setColor(QPalette::Button, Qt::red);
pb->setPlaette(p);
//where pb is QPushButton
omega36
30th October 2008, 13:21
I tried this code, but it just creates a red contour :s
thanks
pastor
30th October 2008, 13:31
Strange... It's working for me fine. What OS are you using?
spirit
30th October 2008, 13:39
yup, this code works fine.
omega36
30th October 2008, 13:45
visual studio 2005 + XP !
pastor
30th October 2008, 14:21
Please show your code and screenshot (if possible of course)
omega36
30th October 2008, 14:40
this is the code :
QPalette p = ui.pushButton->palette();
p.setColor(QPalette::Button, Qt::red);
ui.pushButton->setPalette(p);
the screenshot is not big thing, just a buton for test :o
ypp, I tried with sylesheet but the buton come not clickable:
ui.pushButton->setStyleSheet ("QPushButton {background : rgb(224, 0, 0); border-width: 2px; border-radius: 10px; border-color: beige; font: bold 14px; min-width: 10em; padding: 6px;}");
spirit
30th October 2008, 14:53
try this example.
omega36
30th October 2008, 15:00
thank you for the example, it works just with :
pushButton_2->setStyleSheet("QPushButton {background : rgb(224, 0, 0);}");
The first button has not changed (QPalette)
the second buton come not clickable :confused:
prasanth.nvs
31st October 2008, 08:29
Hi i think this code is working properly..
QPalette lPalette;
lPalette.setColor(pb1->backgroundRole(),QColor(255,0,0));
pb1->setPalette(lPalette);
the above code is correct and u try it...
where pb1 is ur pushbutton:o:o
omega36
31st October 2008, 10:51
even if the above code is correct, but... nothing happend :crying:
and this is my solution : I create a red .png - for exemple - with "MacromediaFireWorks" ,
I convert it to .ico and it's work with this code :
ui.pushButton->setIcon(QIcon("./icon/28.ico"));
thanks to all :)
spirit
31st October 2008, 10:56
it's not a solution. it's woraround. you have to find a problem.;)
spirit
31st October 2008, 11:01
try to de the next thing, open Qt Designer, create a widget and put on it a QPushButton and play with a palette settings of this button. what will you see?
omega36
31st October 2008, 11:49
I dont see any thing :confused::crying:
it's a temporary solution
spirit
31st October 2008, 11:56
did you do this in designer and color of button did not change?
ps. packed by 7zip
omega36
31st October 2008, 12:03
I did the same.. :o
even on the pallette all other controls change color except button
spirit
31st October 2008, 12:05
rebuild Qt and try again :D
pastor
31st October 2008, 12:34
omega36, what version of Qt are you using?
omega36
31st October 2008, 12:57
rebuild Qt and try again :D
:D
I use Qt4.2.2
spirit
31st October 2008, 12:59
maybe it's a bug in this version. anyway, did you try to run this code on another version of Qt?
pastor
31st October 2008, 13:01
omega36, Do you have a chance to try Qt 4.3 or 4.4?
omega36
31st October 2008, 13:11
maybe it's a bug in this version. anyway, did you try to run this code on another version of Qt?
....
No I can't, I must use Qt4.2.2 :o
spirit
31st October 2008, 13:15
in this case, it is not necessary to create an image using an image editor and then load it. you can create an QPixmap in your program and then use it. :)
omega36
31st October 2008, 13:23
even if the above code is correct, but... nothing happend :crying:
and this is my solution : I create a red .png - for exemple - with "MacromediaFireWorks" ,
I convert it to .ico and it's work with this code :
ui.pushButton->setIcon(QIcon("./icon/28.ico"));
thanks to all :)
yes.. done ;)
thank u very much
spirit
31st October 2008, 13:29
I'm talking about this
....
QPixmap pixmap(width, height);
pixmap.fill(Qt::red);
QIcon icon(pixmap);
...
omega36
31st October 2008, 13:47
sorry I read it quickly :D
ok that is better :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.