PDA

View Full Version : How to display 2 widgets on the same space?



schmimona
11th August 2011, 11:00
I have this main window on which I would like to put 2 widgets on the same space, i.e. when the user clicks a button then one of the widgets should come up front and the other be hidden and then change places when clicking another button.

My Widget are of different types: one is a QGLWidget and the other one is a QGraphicsView.

How could I put these 2 widgets on the same place?

qlands
11th August 2011, 11:40
Hi,

If I understand correctly. You can place bot items in the same x,y position. Then one of them can have setVisible(false) from the start. Then with the button you can set one to setVisible(true) and the other setVisible(false), the other button can do the inverse process false,true.

schmimona
11th August 2011, 12:46
yes. something like that. but then how could I set the layout of the main window? because apart from these 2 widgets which should be on the top half of the main window I also have some widgets on the bottom half.

marcvanriet
11th August 2011, 12:49
Why don't you just use a stacked widget to put the 2 upper widgets in ? Then you don't have to do any 'tricks', just select the other page of the stacked widget.

And the other widgets can easily be arranged below this stacked widget, maybe grouped into a frame or groupbox.

Best regards,
Marc

schmimona
11th August 2011, 13:14
really good idea with the stacked widget. it works perfectly now for what i want it to do. thanks. :)

MasterBLB
11th August 2011, 13:18
Read the Assistant about QStackedLayout class