Results 1 to 6 of 6

Thread: Where are the QIcons in QPushButton

  1. #1
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Where are the QIcons in QPushButton

    In Qt Designer there are 8 icons (properties) listed in the QAbstractButton class:
    Normal (on/off)
    Active (on/off)
    Toggled (on/off)
    Selected (on/off)

    I don't actually know (nor can I find) whether these are just *POSSIBLE* storage locations or whether or not somewhere in QAbstractButton it stores these eight QIcons. If someone could advise me as to whether I can use these icons in a derived class or whether I need to provide my own storage that'd be lovely! As it is I've checked source code and documentation up and down and there's nothing pointing me in the direction of these supposed properties. There's not even Q_PROPERTYs declaring what happens for these.

    If these are real QIcons, where are they stored/how do I access them. I don't want to clutter my implementation with needless additional storage if I don't have to. Thanks!

  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: Where are the QIcons in QPushButton

    There is only a single QIcon set on a QAbstractButton using setIcon(). That QIcon can have a pixmap associated with each QIcon::Mode and QIcon::State using QIcon::addPixmap() or QIcon::addFile(). If you do not set a pixmap for a given mode/state then one is derived from the base (normal/off) icon. See the QIcon details.

  3. #3
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Where are the QIcons in QPushButton

    Many thanks for the quick reply. I'm looking at the example and having a hard time how I should be setting the currently displayed icon based on these states and such. Do I really need to take a QPixmap and use the painter directly every time?

    I.E. how do I use QIcon's Mode and State enums to set the current icon based on them. Say I have an Icon:
    Do I set it as Active when I want? If so will it automatically update the icon? If so how do I do this?
    Do I instead derive the pixmap from the state/mode? If so, how do I use this pixmap?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Where are the QIcons in QPushButton

    Why don't you read the docs on QIcon? There is a nice example there showing the concept of different icon modes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    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: Where are the QIcons in QPushButton

    Quote Originally Posted by tescrin View Post
    I.E. how do I use QIcon's Mode and State enums to set the current icon based on them.
    You don't. There is no notion in QIcon of a current state, just a collection of QPixmaps that can be used by classes that render QIcons.
    Say I have an Icon:
    Do I set it as Active when I want? If so will it automatically update the icon? If so how do I do this?
    Do I instead derive the pixmap from the state/mode? If so, how do I use this pixmap?
    If the specific QAbstractButton subclass you are using has a state that has a meaningful mapping to one of the QIcon modes then the button can use the pixmap for that mode when the button paints itself. If you are implementing you own QAbstractButton sub-class and you want it to use the non-default QIcon pixmaps then, yes you do need to account for that in your QWidget::paintEvent().

    For the vast majority of purposes QPushButton or QToolButton are the classes you will be using for button-like behaviour... and they already take care of using a suitable pixmap from the QIcon to match the button's state.

  6. #6
    Join Date
    Jun 2012
    Posts
    98
    Thanks
    11
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Where are the QIcons in QPushButton

    I think I need to redefine the problem more concretely. I'm attempting to design a specific button to be plugged into designer. That's all fine and good. The problem is:

    -I need to know how to manipulate the current mode/state of a qpushbutton. I don't see the enums listed under QAbstractButton nor do I see them under QPushButton. There seem to be no functions for it either. I'm guessing they're there, but I can't find them. This is why I mentioned that I also found no Q_PROPERTYs to clue me into where I should be looking.

    Instead I can add my own modes/states to the button I made, but I feel like there are enough states in QPushButton that this is extraneous. I have to manipulate the image of the button in a specific way, so being able to manipulate/check the current state is important.

Similar Threads

  1. My mode to displaying QIcons
    By Borland in forum Qt Programming
    Replies: 13
    Last Post: 18th March 2012, 18:11
  2. SVG QICONs not appearing after deploy (QT 4.2.2)
    By donmorr in forum Installation and Deployment
    Replies: 2
    Last Post: 29th March 2007, 13:16
  3. QVariant - storing QIcons[]
    By moowy in forum Qt Programming
    Replies: 7
    Last Post: 25th August 2006, 00:41
  4. QIcons
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2006, 13:11
  5. Problems declaring global QIcons
    By SkripT in forum Qt Programming
    Replies: 5
    Last Post: 7th March 2006, 18:08

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.