Qt Forum

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

    Unsolved How to always show my qt widget on top of my parent window but also on top of parent's child widgets?

    General and Desktop
    3
    7
    2050
    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.
    • L
      lachdanan last edited by

      Hi,

      Basically I have a qt widget where I always want it visible on top of everything in the parent window, including other child widgets of the parent window. My widget doesn't have any children.

      My widget is not modal and it should not block any input.

      Lastly I don't want it to be on top of unrelated apps/windows, that's why I can't use WindowStaysOnTopHint, because that makes my widget show up on top of every thing which is not what I want.

      Any ideas?

      Thanks a lot in advance.

      J.Hilk 1 Reply Last reply Reply Quote 0
      • J.Hilk
        J.Hilk Moderators @lachdanan last edited by

        @lachdanan
        after you call show() on your widget, call also raise() on it, it will push it on the top

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

        Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply Reply Quote 1
        • L
          lachdanan last edited by

          Thanks, I just tried it, but just doing mywidget.raise() raises syntax error so I did it using getattr, then call this function, but after that another child window that was below my widget, when it gets focus goes over my widget, because this widget encompasses mine and others and it has to.

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @lachdanan last edited by

            @lachdanan said in How to always show my qt widget on top of my parent window but also on top of parent's child widgets?:

            Thanks, I just tried it, but just doing mywidget.raise() raises syntax error

            Since raise() is a method of QWidget (https://doc.qt.io/qt-5/qwidget.html#raise) you have done something wrong if you get a syntax error.

            L 1 Reply Last reply Reply Quote 0
            • L
              lachdanan @JonB last edited by lachdanan

              @JonB no it's because raise is also a reserved keyword in Python so I can't use it as an instance method, that's why I invoked in dynamically.

              Anyway this technique didn't work for me as I mentioned above.

              JonB 1 Reply Last reply Reply Quote 0
              • JonB
                JonB @lachdanan last edited by JonB

                @lachdanan said in How to always show my qt widget on top of my parent window but also on top of parent's child widgets?:

                no it's because raise is also a reserved keyword in Python so I can't use it as an instance method, that's why I invoked in dynamically.

                It always helps if you get a syntax error if you say you are using Python and not C++.... So did you see e.g. https://doc.qt.io/qtforpython/PySide2/QtWidgets/QWidget.html#PySide2.QtWidgets.PySide2.QtWidgets.QWidget.raise_ or similarly if you are PyQt? That's why they made it raise_() for Python....

                L 1 Reply Last reply Reply Quote 3
                • L
                  lachdanan @JonB last edited by

                  @JonB thx a lot you are right I should have mentioned Python but it will be the same as dynamically calling it. I will give it a try when I go home.

                  Here the last reply basically explains the issue I had with raise:
                  https://stackoverflow.com/questions/2463125/keep-widget-on-top-in-qt

                  There is a much larger child widget that goes in front of mine when it receives focus. This widget is where you do most of the work so it's normal.

                  Mine is supposed to be a monitor you just look at from time to time like cpu monitor. I just want it to always be on top of this app.

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