PDA

View Full Version : Synchronizing "Show XXX window" action checked state with some window's visibility



abey
17th March 2010, 16:23
Hello,

In my soft, I've got a windows and a menu item and related action to control the window's visibility. The action is checkable, so I can do


connect(action, SIGNAL(toggled(bool)), window, SLOT(setVisible(bool)));

Is there an easy way to do the opposite -- ie. have the toggled state of the action updated whenever the visibility of the window changes?

TIA,
Antoine

Lykurg
17th March 2010, 16:31
Yes: QWidget::setHidden().

Edit: Ehm, forget about it, misread:rolleyes:


Edit2: And now the answer: There is no signal but an event: QWidget::showEvent()/QEvent::Show/QEvent::Hide

abey
17th March 2010, 16:42
So the window's parent (say my QMainWindow's subclass) could intercept this event and change the action accordingly, provided that the main windows is somehow the parent of the windows whose visibility we want to track. Is that correct?

Lykurg
17th March 2010, 16:47
Your main window mustn't be the parent. I can think of two options: a) install an event filter on your widgets you want to watch or create an abstract class which must be inherited by your windows. There catch the show and hide event and emit custom signals. Then you can use signal and slots as you are used to.