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)

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

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 912 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 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
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 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
      1
      • Christian EhrlicherC Online
        Christian EhrlicherC Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 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
        0
        • Christian EhrlicherC Christian Ehrlicher

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

          P Offline
          P Offline
          Pythonic person
          wrote on 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
          • Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 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
            1
            • Christian EhrlicherC Christian Ehrlicher

              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 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
              • Christian EhrlicherC Christian Ehrlicher

                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 last edited by Pythonic person
                #6
                This post is deleted!
                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

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

                  • Login

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