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. How to detect focus out event on a widget if it contains child widgets
Forum Updated to NodeBB v4.3 + New Features

How to detect focus out event on a widget if it contains child widgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 5.2k Views 1 Watching
  • 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
    Sivan
    wrote on last edited by Sivan
    #1

    Hi all,

    If I have a widget (let's called it A) which has many level of childrens, with each level, has more than one child; what will be the best way to detect focus out event from widget A. i.e, when I click anywhere outside of widget A. Also note that, widget A can have many other siblings.

    I know that one of the way I can use is to subscribe to QApplication::focusChanged(QWidget* prev, QWidget* next). However, that would be expensive since for every focus change, the slot connected to this signal will be notified, and for every function call I will have to check the ancestor of prev or prev is not equal to widget A.

    Thanks in advance.

    1 Reply Last reply
    1
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Did you look at reimplementing focusin and focusout event handlers of qwidget ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      S 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Did you look at reimplementing focusin and focusout event handlers of qwidget ?

        S Offline
        S Offline
        Sivan
        wrote on last edited by
        #3

        @dheerendra widget A will not even get the focus in or out if the child widget already consumed it (in the case where child widget has focus policy other than NoFocus)

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          Would like child and parent both process focus event or only parent ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sivan
            wrote on last edited by
            #5

            Only the parent. I just want the parent to be notified as long as the mouse is clicked anywhere outside of the parent

            JonBJ 1 Reply Last reply
            0
            • S Sivan

              Only the parent. I just want the parent to be notified as long as the mouse is clicked anywhere outside of the parent

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Sivan
              I'm not sure of the order events happen/who they get (re-)directed to when, but I would be looking at your QWidgets' (or maybe even higher up the tree, like the parent window's) event filter, https://doc.qt.io/qt-5/qobject.html#eventFilter ; maybe have a look at https://stackoverflow.com/a/1990462. That is a centralized place where you could implement your logic without having to act on focusChanged of each child widget, provided you receive some event there....

              S 1 Reply Last reply
              2
              • JonBJ JonB

                @Sivan
                I'm not sure of the order events happen/who they get (re-)directed to when, but I would be looking at your QWidgets' (or maybe even higher up the tree, like the parent window's) event filter, https://doc.qt.io/qt-5/qobject.html#eventFilter ; maybe have a look at https://stackoverflow.com/a/1990462. That is a centralized place where you could implement your logic without having to act on focusChanged of each child widget, provided you receive some event there....

                S Offline
                S Offline
                Sivan
                wrote on last edited by
                #7

                @JonB the child widget's would still be getting the focusIn or focusOut even if the eventFilter is installed at the parent level. What that means is, I will have to install eventFilter for all the children/grandchildren etc of the parent widget, and in the eventFilter function, I need to check if the obj is a child of widget A

                H 1 Reply Last reply
                1
                • S Sivan

                  @JonB the child widget's would still be getting the focusIn or focusOut even if the eventFilter is installed at the parent level. What that means is, I will have to install eventFilter for all the children/grandchildren etc of the parent widget, and in the eventFilter function, I need to check if the obj is a child of widget A

                  H Offline
                  H Offline
                  H.Mahmoodi
                  wrote on last edited by
                  #8

                  @Sivan Same problem here ...
                  I dont want to install event filter on all children(specially if it need to be done recursive! because it even need consider runtime-adding children too)
                  Someone solved it?

                  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