Results 1 to 8 of 8

Thread: setCentralWidget() without deleting prev widget

  1. #1
    Join Date
    May 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default setCentralWidget() without deleting prev widget

    Hello. Sorry for my bad english..

    How can I call setCetralWidget() that previous widget wasn't deleted?

    it is the realization of setCentralWidget():
    void QMainWindow::setCentralWidget(QWidget *widget)
    1. {
    2. Q_D(QMainWindow);
    3. if (d->layout->centralWidget() && d->layout->centralWidget() != widget) {
    4. d->layout->centralWidget()->hide();
    5. d->layout->centralWidget()->deleteLater();
    6. }
    7. d->layout->setCentralWidget(widget);
    8. }

    so, setCentralWidget always call method deleteLater().

    There is some ways to do it, for example:
    centralWidget()->setParent(NULL);
    //then we can use setCentralWidget()

    1) Is there some other ways to do it?
    2) Hmm.. can I redefenition deleteLater() in centralWidget()?
    Last edited by Usernаme; 19th May 2010 at 14:01.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: setCentralWidget() without deleting prev widget

    Can you describe what you want to do?
    Why do you want to delete the central widget?

    If you want your screen to look different at some point, you can try QStackedWidget

  3. #3
    Join Date
    May 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setCentralWidget() without deleting prev widget

    No, I don't want to delete central widget.
    when I call setCentralWidget(), previous widget will be deleted automatically

  4. #4
    Join Date
    May 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setCentralWidget() without deleting prev widget

    I want to place several widgets to my QMainWindow.
    One at the time

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: setCentralWidget() without deleting prev widget

    Ohh, ok.

    Set a QStackedWidget as your central widget, then you can add multiple "central widgets"'.
    http://doc.qt.nokia.com/4.6/qstackedwidget.html

  6. #6
    Join Date
    May 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setCentralWidget() without deleting prev widget

    I need to add one widget to centralWidget, not multiple..
    Just I need that setCentralWidget() don't delete previous widget, because I will use this widget later.
    QStackedWidget can do this work?

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: setCentralWidget() without deleting prev widget

    If I were you, I would already have checked the documentation of QStackedWidget

  8. #8
    Join Date
    May 2010
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: setCentralWidget() without deleting prev widget

    I have read this before, but I have forgotten this.
    Ok. I'll check the documentation of QStackedWidget, thanks!

Similar Threads

  1. Replies: 4
    Last Post: 19th May 2009, 09:06
  2. Rarely crushing application when deleting widget
    By nedlab in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2009, 10:58
  3. Problem with setCentralWidget
    By blm in forum Qt Programming
    Replies: 3
    Last Post: 2nd September 2008, 13:33
  4. Replies: 2
    Last Post: 7th June 2008, 14:12
  5. QMainWindow setCentralWidget from ui widget, Qt4
    By alan in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 14:00

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.