views:

295

answers:

2

How to switch between the two screens in Qt?

for example, i have a button,static text plus a toolbar,now i will add it to a frame and set it as central widget it works well for one window.. what if i move to the next widow? there i need to show some other stuffs like some other button, images etc... and what if i come back to the first view again? there i need to show my old widgets back?.. how to achieve it?

Thanks

A: 

Hey,

I'm not sure I got your problem right but, you could have different scenarios :

1) You could simply use groupboxes... Some widgets in groupbox1, otherWidget in groupbox2, and you display the groupbox you want to use, hiding the others...

2) You could use stackedWidget, which simulates "pages" of widgets stacked on top of eachothers... more informations here : http://qt.nokia.com/doc/4.6/qstackedwidget.html.

3) You could use other way like using tabs : http://doc.trolltech.com/4.6/qtabwidget.html

4) Maybe this example would be useful to you : http://qt.nokia.com/doc/4.6/dialogs-configdialog.html

Hope it helps a bit !

Andy M
Ok andy.. fine.. Thanks..how about updating the menu dynamically when i moves to different views?
Shadow
You could have multiple menus and set the correct one depending on the displayed view ?
Andy M
Hey, andy.. do u know any sample example of stacked-widget..i read the documentation.. its good.. i need some samples..do u know any samples?
Shadow
A: 

I'd recommend checking out Animation/States example (should be in /qt/examples/animation/states/ subdirectory of your Qt installation). It shows how to combine state machine representing application logic with presentation layer and get cool animation effects for free (of course if you don't need eye candy, you can set widgets properties without any animation).

chalup