Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Detect if the user clicked outside a specific frame (lost the focus)
QtWS25 Last Chance

Detect if the user clicked outside a specific frame (lost the focus)

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 666 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.
  • P Offline
    P Offline
    Pythonic person
    wrote on 14 Aug 2022, 09:42 last edited by Pythonic person
    #1

    Hello, I implemented a slide menu by using some animation and QFrame and layouts, and now I want that slide menu to close/hide whenever the user clicks outside it. So how can I achieve that?

    I already implemented the hide/close functionality, I only need a way to detect the user interacts with the GUI.

    As the QMenu, when you click outside it , it will be hidden

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 14 Aug 2022, 10:16 last edited by Christian Ehrlicher
      #4

      Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      P 3 Replies Last reply 14 Aug 2022, 10:23
      1
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 14 Aug 2022, 09:57 last edited by
        #2

        You can use e.g. QWidget::focusOutEvent()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        P 1 Reply Last reply 14 Aug 2022, 10:07
        0
        • C Christian Ehrlicher
          14 Aug 2022, 09:57

          You can use e.g. QWidget::focusOutEvent()

          P Offline
          P Offline
          Pythonic person
          wrote on 14 Aug 2022, 10:07 last edited by
          #3

          @Christian-Ehrlicher , Thank you for your support.
          Actually, I tried that and I put a print("test") in that function to see if it has been called, but it hasn't, and not worked with me.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 14 Aug 2022, 10:16 last edited by Christian Ehrlicher
            #4

            Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            P 3 Replies Last reply 14 Aug 2022, 10:23
            1
            • C Christian Ehrlicher
              14 Aug 2022, 10:16

              Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.

              P Offline
              P Offline
              Pythonic person
              wrote on 14 Aug 2022, 10:23 last edited by
              #5

              @Christian-Ehrlicher
              Well, i guess i did not, I will read the doc about focus policy and get back here.

              1 Reply Last reply
              0
              • C Christian Ehrlicher
                14 Aug 2022, 10:16

                Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.

                P Offline
                P Offline
                Pythonic person
                wrote on 14 Aug 2022, 11:48 last edited by Pythonic person
                #6
                This post is deleted!
                1 Reply Last reply
                0
                • C Christian Ehrlicher
                  14 Aug 2022, 10:16

                  Do you have set the correct focus policy (as described in the documentation) and also enabled mouse tracking? With mouse tracking you can override mouseMoveEvent() to see when it's going at the border and then closing your widget.

                  P Offline
                  P Offline
                  Pythonic person
                  wrote on 15 Aug 2022, 11:44 last edited by Pythonic person
                  #7

                  @Christian-Ehrlicher Thanks it worked correctly :D I have a kinda large project, and somewhere I was setting setFoucs so some kind of widget caused the weird actions.

                  1 Reply Last reply
                  0

                  1/7

                  14 Aug 2022, 09:42

                  • Login

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