PDA

View Full Version : Switching between 2 widgets, both acting as the central widget of mainwindow



kedar
27th September 2012, 14:43
Hello,

I am working on an application that has two modes of operation i.e 2 widgets, one that inherits from the opengl widget and is used for creating a 3D simulation environment and another one that uses the Qwt library for plotting and analysis. I intend to have a toggle switch that switches between these two widgets, since both modes are equally important I do not wish to use one as the central widget and another as a dialog that pops up every time I click a button. Both widgets need a large amount of screen real-estate and hence sharing of space dosn't seem to be an option.

I tried switching between these two widgets using QMainwindow::setCentralWidget(), the problem is that mainwindow takes ownership of the widget after the first call and hence if I set another widget as the central widget the first one is essentially destroyed. Is there some way to implement this functionality.


Thanks
Kedar

Lesiok
27th September 2012, 17:34
Use QStackedWidget as a central widget and add the two previous widgets.

kedar
27th September 2012, 20:09
Thanks Lesiok, did not know such a widget existed.