I have Checkable actions added to a menu. I would like a replica of that menu permanently displayed in a QWidget. I am looking for a way to add a checkable action in menu and a widget so that they ate syncronized.
I have Checkable actions added to a menu. I would like a replica of that menu permanently displayed in a QWidget. I am looking for a way to add a checkable action in menu and a widget so that they ate syncronized.
There is not ready made widget to do so. You will have write you own widget and connect the signal and slots both ways to keep the menu action and widget in sync. Take special care not to connect the signals in a recursive manner.
When you know how to do it then you may do it wrong.
When you don't know how to do it then it is not that you may do it wrong but you may not do it right.
That shouldn't be a problem if the slots check current state vs. new state before doing an emit.
E.g. if you go for a QCheckBox as the in-widget visualization, then it should be save to connecti QCheckBox::toggled() to QAction::setChecked() and QAction::toggled() to QCheckBox::setChecked()
Both setChecked() slots will only emit toggled() if the value passed to them is different to the one the object currently has.
Cheers,
_
Bookmarks