Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. On Qt6, main window fails to show after being hidden, if run without window manager

On Qt6, main window fails to show after being hidden, if run without window manager

Scheduled Pinned Locked Moved Unsolved Qt 6
7 Posts 3 Posters 1.8k Views
  • 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.
  • S Offline
    S Offline
    squirrel
    wrote on 4 May 2022, 22:15 last edited by
    #1

    Hello,

    I am testing an addon to a Python Qt application (Anki) and I ran into a weird problem. Main window, if shown using show(), and hidden using hide(), will not draw when show() is called again. Here's a minimal Python code that can reproduce the issue.

    from PyQt6.QtWidgets import QMainWindow, QApplication
    QApplication([])
    m = QMainWindow()
    m.show()  # this works, the window appears
    m.hide()  # this also works, the window gets hidden
    m.show()  # this does nothing
    

    I am on Windows 10, and to see the above in action I run VcXsrv in the “One large window” mode, and then on WSL2 / Ubuntu I run DISPLAY=$(ip route list default | awk '{print $3}'):0 python and type the above. I also verified that the issue manifests when running with Xvfb, which is how I normally run tests, by calling grabWindow().

    The issue does not manifest if running the same with Qt5, or if running the above code with VcXsrv in the “Multiple windows” mode.

    Any ideas what might be causing this, and if there's a workaround?

    Versions of things:
    Windows 21H2 19044.1654
    Ubuntu 20.04.4 LTS (WSL2)
    Python 3.10.4
    PyQt6 6.2.3, 6.3.0 — the issue exists in both
    PyQt5 5.15.6

    J 1 Reply Last reply 5 May 2022, 12:51
    0
    • S squirrel
      4 May 2022, 22:15

      Hello,

      I am testing an addon to a Python Qt application (Anki) and I ran into a weird problem. Main window, if shown using show(), and hidden using hide(), will not draw when show() is called again. Here's a minimal Python code that can reproduce the issue.

      from PyQt6.QtWidgets import QMainWindow, QApplication
      QApplication([])
      m = QMainWindow()
      m.show()  # this works, the window appears
      m.hide()  # this also works, the window gets hidden
      m.show()  # this does nothing
      

      I am on Windows 10, and to see the above in action I run VcXsrv in the “One large window” mode, and then on WSL2 / Ubuntu I run DISPLAY=$(ip route list default | awk '{print $3}'):0 python and type the above. I also verified that the issue manifests when running with Xvfb, which is how I normally run tests, by calling grabWindow().

      The issue does not manifest if running the same with Qt5, or if running the above code with VcXsrv in the “Multiple windows” mode.

      Any ideas what might be causing this, and if there's a workaround?

      Versions of things:
      Windows 21H2 19044.1654
      Ubuntu 20.04.4 LTS (WSL2)
      Python 3.10.4
      PyQt6 6.2.3, 6.3.0 — the issue exists in both
      PyQt5 5.15.6

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 5 May 2022, 12:51 last edited by
      #2

      @squirrel Does https://doc.qt.io/qt-5/qwidget.html#raise help?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 5 May 2022, 13:39
      0
      • J jsulm
        5 May 2022, 12:51

        @squirrel Does https://doc.qt.io/qt-5/qwidget.html#raise help?

        S Offline
        S Offline
        squirrel
        wrote on 5 May 2022, 13:39 last edited by
        #3

        @jsulm I tried raise() and all possible combinations of methods that had the words such as show, activate, focus, etc in their name, that I could find. As far as I could tell, the window reports that it is not hidden, I can resize and move it, I can grab() it, in other words, it seems to behave like a very respectable window, except that it is not visible.

        (I am not at all well versed in Qt so I might have missed some (obvious) methods, but raise() I did try.)

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JoeCFD
          wrote on 5 May 2022, 14:52 last edited by
          #4

          try to call this first setWindowFlag( Qt::WindowStaysOnTopHint ); before it is set visible. It is likely that some other widget is set to the top. This widget is behind it.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            squirrel
            wrote on 6 May 2022, 11:52 last edited by
            #5

            @JoeCFD the code above only creates one widget, and the display is used only by one application. But-- I tried that (in Python, it became m.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint)), with no effect. Might this be a bug?

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JoeCFD
              wrote on 6 May 2022, 13:51 last edited by
              #6

              you may create a small test case to replicate the issue. The people here will be able to help you out.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                squirrel
                wrote on 6 May 2022, 21:57 last edited by squirrel 5 Jun 2022, 21:58
                #7

                @JoeCFD the first post in this topic contains the code that's needed to replicate the issue. You'll need an X server without a window manager though; I have mentioned how I can get one on Windows but I'm not sure how exactly the setup can be replicated in Linux etc.

                1 Reply Last reply
                0

                5/7

                6 May 2022, 11:52

                • Login

                • Login or register to search.
                5 out of 7
                • First post
                  5/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved