Dock widget resizing issue



  • I have a couple of QDockWidgets in my QMainWindow. Each dock widget contains a different custom QWidget and has been added to the main window using QMainWindow::addDockWidget().

    The problem I am facing is that one of the docks can't be resized at all unless it is first undocked (made floating and then re-docked again). As soon as the dock widget is re-docked everything works as expected and the size of the dock can be changed however I need it.
    Does anyone have an idea what causes that behavior? The widget in the dock widget has the size policy set to expanding, not to fixed.
    Note: I can re-insert the floating dock exactly at the same place as it was before without touching the other docks and it will work. It really just boils down to un-docking and re-docking it to make it become resizable.


  • Lifetime Qt Champion

    Hi,

    Can you show how you setup that dock and its widget ?



  • @SGaist Sure, here you go:
    I removed any non-contributing code such as the signal-slot connections.

    MainWindow::MainWindow()
    {
        // Dock options
        setDockOptions(AnimatedDocks | AllowNestedDocks | AllowTabbedDocks | GroupedDragging);
    
        // Terminal dock
        _terminal = new Terminal;
        QDockWidget* terminalDockWidget = new QDockWidget("Terminal", this);
        terminalDockWidget->setObjectName("Terminal Dock");
        terminalDockWidget->setWidget(_terminal);
        addDockWidget(Qt::BottomDockWidgetArea, terminalDockWidget);
    
        // Tasks list
        _tasksTreeView = new TasksView;
        _tasksTreeView->setModel(Preferences::instance().tasksManager());
        _tasksTreeView->setEnabled(false);
        QDockWidget* tasksDockWidget = new QDockWidget("Tasks", this);
        tasksDockWidget->setObjectName("Tasks Dock");
        tasksDockWidget->setWidget(_tasksTreeView);
        addDockWidget(Qt::BottomDockWidgetArea, tasksDockWidget);
    
        // Navigation dock
        _navigationTreeView = new WorkspaceNavigation;
        _navigationTreeView->setDragDropMode(QAbstractItemView::DragOnly);
        _navigationTreeView->setDragEnabled(true);
        QDockWidget* navigationDockWidget = new QDockWidget("Navigation", this);
        navigationDockWidget->setObjectName("Navigation Dock");
        navigationDockWidget->setWidget(_navigationTreeView);
        setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
        setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
        addDockWidget(Qt::LeftDockWidgetArea, navigationDockWidget);
     }
    
    void MainWindow::createDock(const QStringList& filePaths, const QString& viewerName)
    {
        QDockWidget* firstDock = nullptr;
        for (const QString& filePath : filePaths) {
            // Get the appropriate viewer
            Viewer* viewer = ...
    
            // Create a new dock
            QDockWidget* dock = new QDockWidget(viewer->toolWidgetName(), this);
            dock->setWidget(viewer->toolWidget());
            dock->setObjectName("Dock " + viewer->toolWidgetName());
            addDockWidget(Qt::RightDockWidgetArea, dock, Qt::Horizontal);
    
            // Tab them together
            if (firstDock) {
                tabifyDockWidget(firstDock, dock);
            } else {
                firstDock = dock;
            }
        }
    }
    

    It is the dock that I add in MainWindow::createDock() that shows the issue explained in my first post.
    It doesn't matter whether it creates just one dock (if the passed string list contains just one item) or if it creates multiple ones and tabs them together. In both cases I have to un-dock and re-dock the newly created dock before I can resize it using the mouse/splitters.

    Note: viewer->toolWidget() returns a regular QWidget that contains a layout with other QWidgets as layout items. Nothing special.


  • Lifetime Qt Champion

    The code looks good.

    One thing I would try is to remove the dock options and enable them one by one.



  • I tried what you proposed but sadly without any luck. No matter which dock options I use - I can even leave them to the default ones - the issue remains: I can't resize the dock before I re-dock it.

    Any other ideas or suggestions?


  • Lifetime Qt Champion

    Which version of Qt are you using ? On which platform ?



  • Qt 5.6.0 on Windows 64-Bit using MinGW 4.9.2 32-Bit


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.