PDA

View Full Version : Custom buttons problem



giotto
7th February 2008, 13:57
Hi,

I'd like to create custom buttons.
for example: I've got 2 buttons and I want them different.

How can I do this?

I read the Qt Style Sheets Examples, and there is an example
QPushButton#evilButton { background-color: red }

I guess the evilButton is the name of the QPushButton, but if I create a QPushButton:

for example: QPushButton *hidePreferences;
I can't customize it with the QPushButton#hidePreferences reference.

How can I do this?

giotto

jpn
7th February 2008, 14:13
From Selector Types (http://doc.trolltech.com/latest/stylesheet-syntax.html#selector-types):

ID Selector QPushButton#okButton Matches all QPushButton instances whose object name is okButton.


hidePreferences->setObjectName("hidePreferences");

giotto
7th February 2008, 16:08
From Selector Types (http://doc.trolltech.com/latest/stylesheet-syntax.html#selector-types):



hidePreferences->setObjectName("hidePreferences");

Thanks it works, but only for one object.

If I set up two objectes, with different names, only the firsts' style is changed. If I flips the styles in the stylesheet file than the second is styled :confused:

wysota
7th February 2008, 16:44
Maybe you should answer this question first - what exactly are you trying to obtain? Please provide a little more descriptive explanation.

giotto
7th February 2008, 18:13
Maybe you should answer this question first - what exactly are you trying to obtain? Please provide a little more descriptive explanation.

Well,

I'd like to create ten radiobuttons. These buttons change color of the widget. And I like to set an image for each button. for example: the yellow radiobutton will have a yellow image, the green will have a green image to show the exactly color, which will be set. :)

wysota
7th February 2008, 20:09
It'll be best if you use Designer to layout your buttons. You can then right click each button and choose the option to modify the stylesheet of each button. If you don't want to use Designer, you don't have to - you can use QWidget::setStyleSheet() to style each widget separately.


greenButton->setStyleSheet("background-color: green;");
redButton->setStyleSheet("background-color: red;");
blueButton->setStyleSheet("background-color: blue;");

giotto
7th February 2008, 21:53
Actually, this is how it is working now, but I don't want to burn it into the source. I want to separate the stylesheets, into a qss file, but I don't know how to access it. Somehow I can reach only the first reference.... :confused:

giotto
7th February 2008, 21:56
Damn!

There was a syntax error in the qss file, now everything works fine.... :mad: