PDA

View Full Version : how to get the type of the QMdiSubWindow



xiongxiongchuan
3rd September 2013, 02:21
i have severl different type of widget using in QMdiArea,i want to update the menus and the action status as the widgets changes,i used the
QMdiSubWindow * QMdiArea::activeSubWindow () const the get the current active QMdiSubWindow.but i want to know which widget it is ?
how?
thank you in andvance

ChrisW67
3rd September 2013, 02:39
The return from QMdiArea::activeSubWindow() is always a pointer to a QMdiSubWindow. What you are trying to determine is the class of the widget contained inside the QMdiSubWindow. You can do that with qobject_cast:


QMdiSubWindow *sw = mdiArea->activeSubWindow();
if (sw) {
if (FooWidget *foo = qobject_cast<FooWidget*>(sw->widget())) {
// do something FooWidget specific
}
else if (BarWidget *bar = qobject_cast<BarWidget*>(sw->widget())) {
// do something BarWidget specific
}
}

You probably want to do this work in a slot attached to the subWindowActivated() signal.

If you have widgets of the same class but with different purposes then you could use the QObject::name() to differentiate them.

You could just keep a track of the QMdiSubwindow pointers you got when you created the the sub windows and compare those to the active one.