Results 1 to 4 of 4

Thread: Style QPushButton differently whether has Icon or not?

  1. #1
    Join Date
    Mar 2016
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Question Style QPushButton differently whether has Icon or not?

    Hi,

    Is it possible to style QPushButtons separately from a qss stylesheet whether if it has an icon applied or not? Something like:
    Qt Code:
    1. QPushButton[hasIcon="true"] {
    2. background-color: green;
    3. }
    4. QPushButton[hasIcon="false"] {
    5. background-color: red;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Thank you

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Style QPushButton differently whether has Icon or not?

    If you set a dynamic property "hasIcon" when you set/unset the icon on a button then this should work. While the button already has an icon property I do not think it is usable in this context.

  3. #3
    Join Date
    Mar 2016
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows

    Default Re: Style QPushButton differently whether has Icon or not?

    Thank you ChrisW67, I'm not C++ coder, just a CSS/QT designer... do you know how can I create this dynamic property if I have detected this code?:
    Qt Code:
    1. self.pointButton = self._pushbutton("addButton", bl, icon="Draft_AddPoint", width=100)
    To copy to clipboard, switch view to plain text mode 
    Source code taken from here.

    Thank you

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Style QPushButton differently whether has Icon or not?

    At a guess...
    Qt Code:
    1. if icon:
    2. button.setProperty('hasIcon', 'yes')
    To copy to clipboard, switch view to plain text mode 
    In the_pushbutton() function at line 297 would do it.

Similar Threads

  1. QPushbutton style
    By taih888 in forum Newbie
    Replies: 3
    Last Post: 5th November 2010, 12:18
  2. QPushButton frame style
    By Nippler in forum Qt Programming
    Replies: 4
    Last Post: 5th November 2010, 12:10
  3. Replies: 3
    Last Post: 13th October 2009, 15:31
  4. QPushButton appears differently
    By gianhut in forum Qt Tools
    Replies: 4
    Last Post: 5th January 2009, 22:08
  5. Style QPushButton
    By Rodrigo in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2008, 06: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.