Results 1 to 2 of 2

Thread: MainWindow's child DockWidget disappears if I call setFloating(true)

  1. #1
    Join Date
    Jan 2020
    Qt products
    Qt4 Qt5
    MacOS X Unix/X11 Windows

    Question MainWindow's child DockWidget disappears if I call setFloating(true)

    I've been having some trouble with the QDockWidget class. I've set my QDockWidget instance as a child of my MainWindow, but calling setFloating(true) on the QDockWidget causes it to disappear when I run my program. See below: if I run the code as presented, the dock widget appears with the example strings I added. in the top left of my main window. If I uncomment the line containing setFloating(true), instead I get a completely blank main window. But from what I see in the documentation, dock widgets are floating by default, so I don't think setFloating(true) should even have an effect. Am I missing something, or perhaps am I misunderstanding the meaning of "floating"?

    I am using Qt 5.11.1 on Ubuntu 18.04.

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent)
    3. , ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. m_docker = new QDockWidget(this);
    8. m_docker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    9. //m_docker->setFloating(true);
    11. QListWidget* example_list = new QListWidget(m_docker);
    12. example_list->addItems(QStringList()
    13. << "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
    14. << "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
    15. << "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
    16. << "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
    17. << "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
    18. << "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
    19. m_docker->setWidget(example_list);
    21. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Alameda, CA, USA
    Thanked 711 Times in 701 Posts
    Qt products
    Windows Android

    Default Re: MainWindow's child DockWidget disappears if I call setFloating(true)

    I get a completely blank main window
    According to this code, you have no central widget, so the inside of the main window -should- be blank.

    Is your floating dock widget behind the main window? (Move the main window...)

    What happens if you float the dock widget and call its show() method manually? Could be that docking it forces it to be shown when the main window is shown, but not if it starts out floating.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 11th February 2018, 17:47
  2. Replies: 5
    Last Post: 17th March 2017, 00:20
  3. Replies: 4
    Last Post: 17th August 2010, 19:38
  4. Replies: 1
    Last Post: 15th August 2010, 21:40
  5. Replies: 3
    Last Post: 4th September 2009, 12:49


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.