Results 1 to 3 of 3

Thread: Switching between 2 widgets, both acting as the central widget of mainwindow

  1. #1
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Switching between 2 widgets, both acting as the central widget of mainwindow

    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

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Switching between 2 widgets, both acting as the central widget of mainwindow

    Use QStackedWidget as a central widget and add the two previous widgets.

  3. The following user says thank you to Lesiok for this useful post:

    kedar (27th September 2012)

  4. #3
    Join Date
    Sep 2012
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Switching between 2 widgets, both acting as the central widget of mainwindow

    Thanks Lesiok, did not know such a widget existed.

Similar Threads

  1. Replies: 0
    Last Post: 6th November 2011, 09:22
  2. Replies: 8
    Last Post: 28th June 2011, 14:57
  3. Replies: 19
    Last Post: 3rd January 2011, 21:53
  4. Replies: 5
    Last Post: 30th November 2010, 06:40
  5. QDockWidgets without central widget
    By JoeMerchant in forum Qt Programming
    Replies: 17
    Last Post: 8th August 2007, 14:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.