Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    3
    6
    162
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zandarina last edited by zandarina

      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_.setWindowTitle(tr("Catalog"));
        layout()->addWidget(&dock_toolbar_);
      
      dock_toolbar_.setFeatures(QDockWidget::NoDockWidgetFeatures | QDockWidget::DockWidgetClosable   | QDockWidget::DockWidgetMovable);
      dock_toolbar_.setFloating(true);
      dock_toolbar_.setAllowedAreas(Qt::NoDockWidgetArea);
      

      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
      application

      Thanks for your help

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • gde23
          gde23 last edited by

          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.
          1 Reply Last reply Reply Quote 1
          • Z
            zandarina last edited by zandarina

            @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.

            Thanks

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

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

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply Reply Quote 1
              • gde23
                gde23 last edited by

                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.

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post