Results 1 to 4 of 4

Thread: StyleSheet syntax for children widgets

  1. #1
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default StyleSheet syntax for children widgets

    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...

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: StyleSheet syntax for children widgets

    Have a look at the documentation, article "The Style Sheet Syntax". There, Descendant Selector and Child Selector are what you are looking for.

  3. The following user says thank you to Lykurg for this useful post:

    pan (17th November 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: StyleSheet syntax for children widgets

    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
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #4
    Join Date
    Nov 2010
    Posts
    57
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: StyleSheet syntax for children widgets

    Yep, can't believe I missed those lines
    Sorry to take your time on that one. It's exactly what I wanted.

Similar Threads

  1. Replies: 5
    Last Post: 10th October 2012, 21:05
  2. Replies: 7
    Last Post: 12th January 2011, 22:01
  3. Can I layout widgets by using StyleSheet?
    By MorrisLiang in forum Qt Programming
    Replies: 4
    Last Post: 4th May 2010, 12:20
  4. StyleSheet syntax checking
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 30th June 2008, 10:09
  5. Replies: 3
    Last Post: 29th May 2008, 13:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.