Results 1 to 2 of 2

Thread: addDockWidget && removeDockWidget trouble

  1. #1
    Join Date
    Jan 2006
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default addDockWidget && removeDockWidget trouble

    Hello all!

    This code is a part of my MainWindow class constructor
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. ....
    4. dock = new QDockWidget(tr("Paragraphs"), this);
    5. QLineEdit* l = new QLineEdit(0);
    6. dock->setWidget(l);
    7. dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
    8. dock->setFloating(false);
    9. addDockWidget(Qt::BottomDockWidgetArea, dock);
    10. ....
    11. }
    To copy to clipboard, switch view to plain text mode 

    It works fine!

    Why this code is incorrect (dock widget is invisible):
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. ....
    4. dock = new QDockWidget(tr("Paragraphs"), this);
    5. QLineEdit* l = new QLineEdit(0);
    6. dock->setWidget(l);
    7. dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
    8. dock->setFloating(false);
    9. addDockWidget(Qt::BottomDockWidgetArea, dock);
    10. removeDockWidget(dock); /// Remove
    11. addDockWidget(Qt::BottomDockWidgetArea, dock); /// And add again
    12. ....
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: addDockWidget && removeDockWidget trouble

    Removing the dock widget causes it to be hidden.

    Docs say:
    void QMainWindow::removeDockWidget ( QDockWidget * dockwidget )
    Removes the dockwidget from the main window layout and hides it. Note that the dockwidget is not deleted.

    So if you want to remove and add the same dock widget back and forth, you will have to explicitly call show() to get it visible again.

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
  •  
Qt is a trademark of The Qt Company.