I'm trying to use dock widgets on the main window class in Qt5. However, when I set the central widget to have a fixed height Qt has trouble docking the windows to the top or bottom. Basically, it looks like there is some "padding" or "margins" above and below the central widget. If I set an auto height on the widget, the docking works fine all they way edge-to-edge (top/bottom). How can I either remove the margins or enable the docking function while using a fixed height central widget?
See screenshots for example.
Dock Right w/ Auto Height (No Margins on Central Widget)
Dock Bottom w/ Auto Height (No Margins on Central Widget)
Dock Bottom w/ Fixed Height (Margins/Padding--Grey areas, won't dock)
Here is the code if that helps.
Header:
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QString);
~MainWindow();
private:
void createDockWindows();
QListWidget *m_dock_list;
QString m_directory;
QWidget *m_mainWidget;
};
Class definition:
MainWindow::MainWindow(QString program)
: m_directory(".")
{
m_mainWidget = new QWidget;
m_mainWidget->setFixedHeight(156);
m_mainWidget->setStyleSheet("background-color: blue;");
createDockWindows();
// set central widget and default size
setCentralWidget(m_mainWidget);
}
// dock functions
void MainWindow::createDockWindows()
{
QDockWidget *dock = new QDockWidget(tr("Dock List"), this);
dock->setAllowedAreas(Qt::LeftDockWidgetArea |
Qt::RightDockWidgetArea |
Qt::BottomDockWidgetArea);
m_dock_list = new QListWidget(dock);
m_dock_list->addItems(QStringList()
<< "item 1"
<< "item 2"
<< "item 3"
<< "item 4");
dock->setWidget(m_dock_list);
addDockWidget(Qt::RightDockWidgetArea, dock);
}