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:
- 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()));
3 replies
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() [doc.qt.nokia.com] ?
- 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()));
for some reason I could not find it in the header file.
It’s almost always a better idea to look at the fine API docs using Qt Assistant or the online docs [doc.qt.nokia.com]. The header files do not contain the descriptions.
You must log in to post a reply. Not a member yet? Register here!



