PDA

View Full Version : QToolbutton:checked -> QIcon:selected not working



tomf
20th March 2010, 18:59
I'm trying to show a specific icon when my qtoolbutton is checked - so far without success.

My workflow:
1. create a qmaindindow in qdesigner
2. add a toolbar
3. add an action and make it checkable
4. add an icon to the action for all states (normal off/on, active off/on, selected off/on). All icons are in a resource file.
5. test it.

At first the default (normal) icon is shown. On mouseover the active icon is shown. So far so good. But when I click my qtoolbutton and it is in its checked state the active icon is shown again. Why is the active icon shown and not the selected icon? How can I change this behaviour?

Lykurg
20th March 2010, 19:19
please show us your code for 4.

tomf
21st March 2010, 13:01
I set the icons in qdesigner.

But I also tried this:


_asc_icon.addFile(":/Icons24/sort_asc_normal", QSize(24,24), QIcon::Normal, QIcon::On);
_asc_icon.addFile(":/Icons24/sort_asc_active", QSize(24,24), QIcon::Active, QIcon::On);
_asc_icon.addFile(":/Icons24/sort_asc_selected", QSize(24,24), QIcon::Selected, QIcon::On);

Lykurg
21st March 2010, 13:16
Ah, selected != checked.. Selected means if your action has keyboard focus. I guess you have to use style sheets or subclass QAction.

tomf
21st March 2010, 21:17
Thats odd. But thx!

I wrote my own QToolButton implementation (handling checkStateSet and nextCheckState) and it works fine now.