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. Focus on QAction
Qt 6.11 is out! See what's new in the release blog

Focus on QAction

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.9k 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
    swarsi
    wrote on last edited by
    #1

    suppose i have QAction and this action is being used by toolbuttons and menu items. is there anyway for me to detect when the underlying widget gets/loses focus?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      What 'underlying' widget? A QAction is not a visual element.

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

        some more details will help here. What is the relation of QAction to other widget ? What is the underlying widget etc.

        Also it is good check the focusInEvent handler.

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          swarsi
          wrote on last edited by
          #4

          the QAction could be tied to multiple widget and i wanted to see if any of the underlying widgets had focus. therefore, i am thinking of doing the following by tying the hovered signal from QAction to a slot with the following coding:

          QList <QWidget *> widget_list = sender()->associatedWidgets();

          for(i = 0; i != widget_list.size(); ++i) {
          if (widget_list.at(i)->hasFocus())
          then do something
          else
          do something else
          }

          i think this will work?

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

            on second thought the hovered signal is not good enough because then i could never detect then an underlying widget has lost focus. so i am still not sure for the next step.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              swarsi
              wrote on last edited by
              #6

              what i really need is an enter/leave event on a QAction which i don't think is available.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                Indeed, it's not. A QAction doesn't have a "physical" representation. What you could do is create an action manager that would react when your widgets get/lose their focus.

                Hope it helps

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  swarsi
                  wrote on last edited by
                  #8

                  you are not talking about a QActionGroup here right? what is an action manager an example would be helpful.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Indeed

                    An action manager is a central object where you handle e.g. the redirection of the signals and slots based on your current widget or the shortcuts

                    IIRC, Qt Creator has such a concept, you can have a look at the sources

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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