PDA

View Full Version : QActionGroup question



maverick_pol
5th October 2007, 12:24
Hi gusy,

I have 10 action and I have added them to a QActionGroup. Only one action can be active at time and it's ok, but I need the case when any of the actions is active. But I can't do it. Is is possible to set some settings for QActionGroup so any or only one action could be active an the same time?
(one active at the same time is default setting)

Thanks

Maverick

marcel
5th October 2007, 12:27
actionGroup->setExclusive(true);

Edit: forget it.

jacek
5th October 2007, 12:27
How about setting the exclusive property to false?

maverick_pol
5th October 2007, 12:35
If you want to group checkable actions without making them exclusive, you can turn of exclusiveness by calling setExclusive(false)

Does this mean than I can have no active actions? I understand as I can have more than one active action in the same time, but not any.

Will check it anyway.

Thanks

maverick_pol
5th October 2007, 13:02
setExclusive->(false); enables disactivating all actions(that's what is correct), but also enables 2 or more actions to be active at the same time, and I can't have this kind of solution.

Maverick

jacek
5th October 2007, 13:14
Does it mean that you want to be able to check only 0 or 1 action?

Edit: a quick solution is to add "none" or similar action and let user select it instead.

maverick_pol
5th October 2007, 13:32
Yes 0 or 1.

Thanks

jpn
6th October 2007, 19:34
One idea that comes to my mind is to switch between exclusive and non-exclusive group on the fly. More or less something like this:


class ActionGroup : public QActionGroup
{
Q_OBJECT
public:
ActionGroup(QObject* parent = 0) : QActionGroup(parent)
{
setExclusive(true);
connect(this, SIGNAL(hovered(QAction*)), this, SLOT(actionHovered(QAction*)));
}

private slots:
void actionHovered(QAction* action)
{
setExclusive(action != checkedAction() || !action->isChecked());
}
};