I'm trying to get my QMainWindow to allow only tabbed QDockWidgets. If I understood the Qt Documentation right it should work with the setDockOptions-method.
The following code didn't work for me:
QMainWindow window;
window.setDockOptions(QMainWindow::ForceTabbedDocks);
What am I doing wrong? Or is it a bug in the current Qt version? I'm coding on a MacPro an I'm using Qt 5.7.
thanks
ForceTabbedDocks
only applies to user interactions with the docks.
To programatically add new docks in tabs, you need to use QMainWindow::tabifyDockWidgets
. For example,
void MainWindow::addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget)
{
QList<QDockWidget*> allDockWidgets = findChildren<QDockWidget*>();
QVector<QDockWidget*> areaDockWidgets;
for(QDockWidget *w : allDockWidgets) {
if(dockWidgetArea(w) == area) {
areaDockWidgets.append(w);
}
}
if(areaDockWidgets.empty()) {
// no other widgets
addDockWidget(area, widget);
} else {
tabifyDockWidget(areaDockWidgets.last(), widget);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With