PDA

View Full Version : QAction inside QWidget



mqt
11th October 2013, 18:09
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.

Santosh Reddy
12th October 2013, 07:39
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.

anda_skoa
12th October 2013, 11:15
Take special care not to connect the signals in a recursive manner.

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,
_