alexandergetka
22nd January 2020, 21:57
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.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_docker = new QDockWidget(this);
m_docker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
//m_docker->setFloating(true);
QListWidget* example_list = new QListWidget(m_docker);
example_list->addItems(QStringList()
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
<< "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
<< "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
<< "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
m_docker->setWidget(example_list);
}
I am using Qt 5.11.1 on Ubuntu 18.04.
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_docker = new QDockWidget(this);
m_docker->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
//m_docker->setFloating(true);
QListWidget* example_list = new QListWidget(m_docker);
example_list->addItems(QStringList()
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
<< "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
<< "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
<< "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
m_docker->setWidget(example_list);
}