Important: Please read the Qt Code of Conduct -

QDockWidget windows disappears when I go to other windows and the main one gets blocked

  • Hello,

    I have a doubt. I have the main windows and a catalog is shown when I click a button I create another sub-windows using a QDockWidget

    dock_toolbar_.setFeatures(QDockWidget::NoDockWidgetFeatures | QDockWidget::DockWidgetClosable   | QDockWidget::DockWidgetMovable);

    But the problem is when I change to another window, the subwindows disappears and the main one gets blocked- I have to close the program because I get all blocked.

    Someone know how to leave this window active even if I go to the main window or I go to another

    Thanks for your help

  • Lifetime Qt Champion


    What version of Qt are you using ?
    On what OS ?
    Can you provide a minimal compilable example that shows that behaviour ?

  • There are two things here to consider:

    • The behavior, that when you set the focus onto another application the dockwidgets disappear is normal.
      One way to change this is to use native window decorations with the widgets, however this will cause some other difficulties with docking. This can be done by:
    setWindowFlags(Qt::Dialog | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);

    What is the reason you use a dockwidget and not a dialog when you set Qt::NoDockWidgetArea?

    • the mainwindow gets blocked and the application freezes: I cannot reproduce this from your code. Can you provide a minimal exaple where it happens?
      Another thing: you should not add your DockWidget to the mainwindow layout, but I don't think that's the problem here.

  • @zandarina said in QDockWidget windows disappears when I go to other windows and the main one gets blocked:

    Hi thank you for answering. The version of qt is 5.12.3. I think I understand the problem now. The application freezes because we do not want to make changes until the dockwidget is closed. If the user closes it well, the main window is enabled again. The problem is that if the widget closes by itself, and this is a normal behaviour, this piece of code to enable the main window when the catalogue is closed by the user is never reached so I cannot enable it anymore. So the applications gets blocked and I need to re-start.

    I can use the flags you mentioned to keep it open even if I change to another window but you mentioned some issues. What issues would it be?. Because I think it would be the solution to my problem. Another option is not to block my main windows but then the user can do weird things.


  • Lifetime Qt Champion

    From your description, it looks like you should rather use a window modal dialog. It will disable its parent widget until closed.

  • The issues I mentioned are just with the docking, since it will not work as usually by drag and drop with native decotation, so if you don't want to dock the window anyway it will work totally fine. However then you do not need a QDockWidget at all, and a modal dialog as SGaist suggested should be the best choice.

Log in to reply