PDA

View Full Version : switching between pages



Kapil
6th March 2006, 09:12
Hi,

I have developed few ui pages: Sample1.ui, Sample2.ui, Sample3.ui....

Now what i want is that on button click of Sample1.ui, my page Sample2.ui gets loaded and Sample1.ui gets closed...

To close it i got the function MainWindow.close()...

But am not able to get any function for swtiching between pages...

Please help me finding the solution to it...

Thanking you,
Kapil

jpn
6th March 2006, 09:18
The QStackedWidget (http://doc.trolltech.com/4.1/qstackedwidget.html)class provides a stack of widgets where only one widget is visible at a time.
Load and add your page widgets to a stacked widget, and then just switch the currently shown page widget according to the button click..

Kapil
6th March 2006, 09:24
Hi,

This means that what i have to do is that create a slot, and then on the signal button click i will execute that slot which will load the required Form using the function addwidget().

Is this what u meant?

If not then plz try to open up a bit on the use of QStackedWidget...

Thanking you,
Kapil

jpn
6th March 2006, 09:46
This means that what i have to do is that create a slot, and then on the signal button click i will execute that slot which will load the required Form using the function addwidget().

You should add (http://doc.trolltech.com/4.1/qstackedwidget.html#addWidget) your page widgets to the stacked widget only once (eg. in some constructor or so). Then, according to button click signals, your custom slot should decide which widget in the stack to set as current (http://doc.trolltech.com/4.1/qstackedwidget.html#currentIndex-prop).

jpn
6th March 2006, 09:50
Actually you could add your buttons in a QButtonGroup with id's corresponding page indexes in the stack widget. Then you don't need a custom slot and you can connect button group's buttonClicked(int) signal directly to the stack widget's setCurrentIndex(int) slot.

jpn
6th March 2006, 10:16
Maybe you could also consider using a tab widget?

Anyway check this example, it might help:

wysota
6th March 2006, 10:24
Maybe you should just use separate forms and show() one and close() the other?

Kapil
6th March 2006, 11:50
Hi,

I tried doing the same but am getting lots of errors.. Also i am new to C++ so i am also getting errors 'coz of C++...

I haev attached the code.. Plz help me in finding out the errors...

thanking you,
Kapil

wysota
6th March 2006, 11:53
See the FAQ for details (http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_designer_2f orms)

wysota
6th March 2006, 11:57
In your code:

void ActionClass::actionSlot()
{
secondpg = new QWidget;
Ui_Second::Form _ui;
_ui.setupUi(secondpg);

firstpg->close();
secondpg->show();

}

You can't access "firstpg" like this. You need a pointer to it somewhere. I suggest you work a bit more on learning pure C++ before using Qt.