2
votes

I am trying to position N.5 QDockWidget according to the following lay-out in Figure 1 below:

QDockWidget For some reasons when I add the second and the third QDockwidget on the QMainWindow they are positioned in a very different way and I don't understand if there is a problem for the anchorage. Therefore the fourth and the fifth QDockWidget are positioned even in a more strange way.

Can someone explain how to achieve the lay-out of Figure 1? Thanks for pointing in the right direction

1

1 Answers

2
votes

The design using Qt Designer:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget"/>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>27</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
  <widget class="QDockWidget" name="dockWidget">
   <attribute name="dockWidgetArea">
    <number>1</number>
   </attribute>
   <widget class="QWidget" name="dockWidgetContents"/>
  </widget>
  <widget class="QDockWidget" name="dockWidget_2">
   <attribute name="dockWidgetArea">
    <number>1</number>
   </attribute>
   <widget class="QWidget" name="dockWidgetContents_2"/>
  </widget>
  <widget class="QDockWidget" name="dockWidget_5">
   <attribute name="dockWidgetArea">
    <number>8</number>
   </attribute>
   <widget class="QWidget" name="dockWidgetContents_3"/>
  </widget>
  <widget class="QDockWidget" name="dockWidget_3">
   <attribute name="dockWidgetArea">
    <number>2</number>
   </attribute>
   <widget class="QWidget" name="dockWidgetContents_6"/>
  </widget>
  <widget class="QDockWidget" name="dockWidget_4">
   <attribute name="dockWidgetArea">
    <number>2</number>
   </attribute>
   <widget class="QWidget" name="dockWidgetContents_7"/>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

With C++ code:

#include <QtWidgets>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QMainWindow w;

    QDockWidget *dock_widget_a = new QDockWidget;
    w.addDockWidget(Qt::LeftDockWidgetArea, dock_widget_a);
    QDockWidget *dock_widget_b = new QDockWidget;
    w.addDockWidget(Qt::LeftDockWidgetArea, dock_widget_b);

    QDockWidget *dock_widget_c = new QDockWidget;
    w.addDockWidget(Qt::RightDockWidgetArea, dock_widget_c);
    QDockWidget *dock_widget_d = new QDockWidget;
    w.addDockWidget(Qt::RightDockWidgetArea, dock_widget_d);

    QDockWidget *dock_widget_e = new QDockWidget;
    w.addDockWidget(Qt::BottomDockWidgetArea, dock_widget_e);

    w.setCentralWidget(new QWidget);
    w.resize(640, 480);
    w.show();
    return a.exec();
}

enter image description here