How to set the initial state of a menu action
-
I see that the infeace fo a ction let you do this
@ void setCheckable(bool);
bool isCheckable() const;bool isChecked() const;@
however some time a menu initial state must be checked, or sometime you set it condionally base on xml config file
but I can not see how to do it a creation time:
something like this:@QAction* action = new QAction(this);
action->setText(QApplication::translate("newtonMain", "Autosleep dissabled", 0, QApplication::UnicodeUTF8));
action->setCheckable(true);
// here I'd like to force this action on condiotinally
if (m_autosleep) {
action-> .....
}subMenu->addAction(action);
connect (action, SIGNAL (triggered(bool)), this, SLOT (OnAutoSleep()));@ -
Huh? I don't think I understand this exactly.
You want to set whether it is checked based on the condition of m_autosleep?
Don't you just use "setChecked()":http://doc.qt.nokia.com/latest/qaction.html#checked-prop ?@
QAction* action = new QAction(this);
action->setText(QApplication::translate("newtonMain", "Autosleep dissabled", 0, QApplication::UnicodeUTF8));
action->setCheckable(true);
action->setChecked(m_autosleep);subMenu->addAction(action);
connect (action, SIGNAL (triggered(bool)), this, SLOT (OnAutoSleep()));
@ -
Oh thank you
@action->setChecked(m_autosleep); @
is what I was looking for, for some reason I could not find it in the header file.
and yes you are right, I can just call it without testing the condition.Thank you.
-
[quote author="julio jerez" date="1298207592"]for some reason I could not find it in the header file.[/quote]
It's almost always a better idea to look at the fine API docs using Qt Assistant or the "online docs":http://doc.qt.nokia.com/. The header files do not contain the descriptions.