Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Place a Dock widget programatically



  • Hello
    I need to move the position of a dock widget from within my program after it has been initially created and displayed.
    I tried this
    @
    removeDockWidget(m_jobDetailsDockWidget);
    removeDockWidget(m_eventCriteriaDockWidget);
    addDockWidget(Qt::BottomDockWidgetArea,m_jobDetailsDockWidget);
    addDockWidget(Qt::BottomDockWidgetArea,m_eventCriteriaDockWidget);
    @
    But the dock widgets are removed but not re displayed.

    I have amended my code -
    @
    m_allowDockingAction->setChecked(false);
    removeDockWidget(m_jobDetailsDockWidget);
    removeDockWidget(m_eventCriteriaDockWidget);
    bool bb = m_jobDetailsDockWidget->isFloating();
    m_jobDetailsDockWidget->setFloating(false);
    bb = m_jobDetailsDockWidget->isFloating();
    addDockWidget(Qt::BottomDockWidgetArea,m_jobDetailsDockWidget);
    addDockWidget(Qt::BottomDockWidgetArea,m_eventCriteriaDockWidget);
    m_jobDetailsDockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
    m_eventCriteriaDockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
    //m_jobDetailsDockWidget->toggleViewAction()->activate(QAction::Trigger);
    m_jobDetailsDockWidget->show();
    m_eventCriteriaDockWidget->show();
    tabifyDockWidget(m_eventCriteriaDockWidget,m_jobDetailsDockWidget);
    @

    This now works as expected UNLESS one of the docked widgets is floating in which case the docked widget remains floating even tho I call setFloating(false)

    How can I overcome this?

    Thanks

    Is there a trick to this?

    Thanks


  • Lifetime Qt Champion

    removeDockWidget hides the widget, so a simple setVisible(true) should show it.

    But first thing, why don't you initialize your docks at the right place ? (Since your remove all dock features in your second code snippet)


Log in to reply