Results 1 to 6 of 6

Thread: Is it possible to logically combine dynamic properties in a Qt Stylesheet?

  1. #1
    Join Date
    Jun 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Is it possible to logically combine dynamic properties in a Qt Stylesheet?

    I would like to have logical AND comparison using dynamic properties, but can't figure out the syntax, or if it is even possible.
    Lets say I want to do something special to a QPushButton if it has both an icon and text. I know how/when to set the peoperties but can't figure out the stylesheet syntax.

    First I set these separate cases fine:
    Qt Code:
    1. MyButton[hasIcon="true"] {background-color: pink;}
    2. MyButton[hasText="true"] {background-color: blue;}
    To copy to clipboard, switch view to plain text mode 
    But none of these will set the background to green:
    Qt Code:
    1. MyButton[hasIcon="true"] MyButton[hasText="true"] {background-color: green;}
    2. MyButton[hasIcon="true"],[hasText="true"] {background-color: green;}
    3. MyButton[hasIcon="true"][hasText="true"] {background-color: green;}
    To copy to clipboard, switch view to plain text mode 
    If it isn't possible could someone please let me know so I can stop chasing my tail?

  2. #2
    Join Date
    Oct 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?

    Did you ever get anywhere with this?


    Added after 21 minutes:


    In 5.5 the following works:

    Qt Code:
    1. MyButton[hasIcon="true"][hasText="true"] {background-color: green;}
    To copy to clipboard, switch view to plain text mode 
    Last edited by skebanga; 28th October 2015 at 19:31.

  3. #3
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?

    Try using the full attribute selectors, separated by a comma. The OP did not try it.
    http://stackoverflow.com/a/9536746/4206247

    The name of this construct is "group selectors," and seems to be standard CSS.

  4. #4
    Join Date
    Oct 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?

    That's an OR selector

    So given the following, if MyButton has hasIcon OR hasText true, it will set background to blue

    Qt Code:
    1. MyButton[hasIcon="true"],MyButton[hasText="true"] {background-color: blue;}
    To copy to clipboard, switch view to plain text mode 

    What OP wanted as an AND selector

    Given the following, if MyButton has hasIcon AND hasText true, it will set background to blue

    Qt Code:
    1. MyButton[hasIcon="true"][hasText="true"] {background-color: blue;}
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?

    I understand. Given that the AND selector is valid CSS, it mustn't be something supported by the Qt interpreter right now. Perhaps request it to be implemented?

    Just so this doesn't stop you, if you can know which buttons have both text and icon, you can add any custom property to flag the button, like...
    myButton.setProperty( "hasIconAndText", true );

    And then use a selector for that.

  6. #6
    Join Date
    Oct 2015
    Posts
    7
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Is it possible to logically combine dynamic properties in a Qt Stylesheet?

    It actually is working - I just just following up on the fact that it was

Similar Threads

  1. QObject dynamic properties and QML binding
    By ugluk in forum Qt Quick
    Replies: 5
    Last Post: 22nd December 2012, 00:43
  2. Replies: 1
    Last Post: 20th January 2011, 18:17
  3. dynamic properties
    By Hogwarts in forum Qt Programming
    Replies: 1
    Last Post: 3rd May 2010, 17:37
  4. QTabWidget stylesheet properties
    By Prompt in forum Qt Programming
    Replies: 0
    Last Post: 18th March 2009, 21:29
  5. How avoid translation of dynamic properties
    By thomas_-_s in forum Qt Tools
    Replies: 1
    Last Post: 19th October 2008, 23:02

Tags for this Thread

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.