PDA

View Full Version : A Question about stackedwidget



anafor2004
29th March 2008, 14:42
Hi All,
I have a question about stacked widget.I have created a widget with Qt designer and I added it on stacked widget.But I wonder how can i check which page is opened on stacked widget.May be my explanation is not enough i added some codes here please look at it.

This part i decleared zemin and i add to stackedwidget.
cpp code


zemin=new cEkrani;
zemin->loadMod(false);
ui.stackedWidget->addWidget(zemin);
ui.stackedWidget->setCurrentWidget(zemin);

This part i want to check is zemin page opened or not but i couldn't do this


if(ui.stackedWidget->currentWidget()==zemin)
{
....
.....
}

How can i do this control with the name of widget?

tbscope
29th March 2008, 14:57
You can use indexOf and currentIndex
http://doc.trolltech.com/4.3/qstackedwidget.html#indexOf

Example in pseudocode:


if(stackedwidget.indexOf(myWidget) == stackedwidget.currentIndex())
{
...
}

By the way: your method should work too.

The documentation isn't really clear about this, but it says that the widgets need to have the stackedwidget as parent. Only looking at the documentation I'm not sure that using addWidget makes the widget a child of the stackedWidget.

I guess it might not hurt to also do:
zemin=new cEkrani(ui.stackedWidget);