PDA

View Full Version : StyleSheet syntax for children widgets



pan
17th November 2010, 13:17
I've searched for a solution to this but to no avail.

I have a form which contains some QPushButtons and a widget (NumberPad) which also contains some QPushButtons. I want to load a single StyleSheet in the form and have two settings for QPushButton; one within the NumberPad widget and one for the others.

QPushButton { ...some Style... } obviously changes them all.

I've tried NumberPad::QPushButton and # etc... I'm not sure how it should work, if at all?

The only solution I can think of, is to create my own MyPushButton and NumPadPushButton and inherit QPushButton. Then in my StyleSheet call these classes like:
.NumPadPushButton{ ....}
.MyPushButton{ ... }
But I'd prefer not to do this just for a style...

Lykurg
17th November 2010, 13:37
Have a look at the documentation, article "The Style Sheet Syntax". There, Descendant Selector and Child Selector are what you are looking for.

high_flyer
17th November 2010, 13:39
The only solution I can think of, ...
Why not check the docs?
http://doc.trolltech.com/4.7/stylesheet-syntax.html

You can specify specific instances:

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

EDIT: ah, beat to it by Lykurg.
Of course, he is right, child and Descendant electrons are also good in your case

pan
17th November 2010, 13:50
Yep, can't believe I missed those lines :(
Sorry to take your time on that one. It's exactly what I wanted.