QAbstractButton has the icon property, which holds a QIcon variable. Take a look at QIcon documentation - This class allows you to specify separate images for different icon states.
QAbstractButton has the icon property, which holds a QIcon variable. Take a look at QIcon documentation - This class allows you to specify separate images for different icon states.
Try using a QToolButton instead of a QPushButton.
You also can use a simple QWidget as a base class and then reimplement mouse press events and emit a clicked signal by your own...
How can I specify different images for different modes in QIcon? I've seen that there is an enum "Mode" to identify the state, but I don't see how to add different images to the Icon representing the modes ...Take a look at QIcon documentation - This class allows you to specify separate images for different icon states.
Last edited by BenPa; 4th February 2010 at 10:02. Reason: Added quote ..
You can connect a slot to the button, check the state, and set the correct icon for the given state.
==========================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.
But for what do I need the "Mode" enum defined in the QIcon class? I don't see a function to set a mode for a QIcon. Using different modes in a icon makes sense to show different states, but if I have to implement this functionality myself, I don't understand for what the mode is defined in the class..
Thank you for the tip.
Its all in the QIcon documentation.
Qt can generate disabled/selected icons automatically using widely used conventions.
If these conventions suit you, you can certainly use these auto generated icons.
QPushButton will show the icons correctly depending on the state.
But your case is different, since you want to use different images for various states, so you have to implement it your self.
==========================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.
You don’t set the mode of a QIcon; you choose the desired mode and state when you paint the icon with QIcon::paint or retrieve an image with QIcon::pixmap. When using a class derived from QAbstractButton, the button takes care of painting the appropriate image depending on the mode and state of the button, so you can add all the images to the icon and then be concerned only with the mode and state of the button, without thinking any further about the icon.
Use QIcon::addFile or QIcon::addPixmap.
If your use fits within the paradigm of four modes (normal, disabled, active and selected) and two states (on and off), you can use this method to specify up to eight images for one QIcon. If that matrix does not reasonably represent the set of images you need, then you’ll need to develop your own method of switching images; you could do that in various ways, such as by re-implementing QWidget::paintEvent or by calling QAbstractButton::setIcon whenever the correct image to display changes.
Bookmarks