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. Move Mouse when tab clicked on keyboard
QtWS25 Last Chance

Move Mouse when tab clicked on keyboard

Scheduled Pinned Locked Moved Solved General and Desktop
key eventmousemovemouse
7 Posts 3 Posters 2.4k 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.
  • H Offline
    H Offline
    HunterMetcalfe
    wrote on 19 Jul 2016, 13:34 last edited by
    #1

    Hi everyone,

    Quick question - is there anyway that when the tab button is clicked on the keyboard, you can set the mouse position to the location of the tab focus that was set by tabbing through a QWidget? For example, if I have 5 rows. As I tab, not only should the focus change, the mouse will move to the row that has the focus. I'm sure I need to use the OnKeyEvent Class. I will also want this functionality to be used inherently by multiple QWidgets. Thank you ahead of time for any input you may have!

    R 1 Reply Last reply 19 Jul 2016, 13:39
    0
    • H HunterMetcalfe
      19 Jul 2016, 13:34

      Hi everyone,

      Quick question - is there anyway that when the tab button is clicked on the keyboard, you can set the mouse position to the location of the tab focus that was set by tabbing through a QWidget? For example, if I have 5 rows. As I tab, not only should the focus change, the mouse will move to the row that has the focus. I'm sure I need to use the OnKeyEvent Class. I will also want this functionality to be used inherently by multiple QWidgets. Thank you ahead of time for any input you may have!

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 19 Jul 2016, 13:39 last edited by raven-worx
      #2

      @HunterMetcalfe

      QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
      

      As starting point you can reimplement focusNextPrevChild(bool) method (which will be called when the focus should be set to the next/previous widget when TAB/BACKTAB is pressed).

      bool MyWidget::focusNextPrevChild( bool next )
      {
             bool result = BaseClass::focusNextPrevChild( next );
             if( result )
             {
                  if( QWidget* widget = QApplication::focusWidget() )
                      QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
             }
             return result;
      }
      

      The caveat is that this has to be done for every widget type. Thus you may want to write this code into a macro (with base class parameter) instead?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      H 3 Replies Last reply 19 Jul 2016, 13:50
      1
      • R raven-worx
        19 Jul 2016, 13:39

        @HunterMetcalfe

        QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
        

        As starting point you can reimplement focusNextPrevChild(bool) method (which will be called when the focus should be set to the next/previous widget when TAB/BACKTAB is pressed).

        bool MyWidget::focusNextPrevChild( bool next )
        {
               bool result = BaseClass::focusNextPrevChild( next );
               if( result )
               {
                    if( QWidget* widget = QApplication::focusWidget() )
                        QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
               }
               return result;
        }
        

        The caveat is that this has to be done for every widget type. Thus you may want to write this code into a macro (with base class parameter) instead?

        H Offline
        H Offline
        HunterMetcalfe
        wrote on 19 Jul 2016, 13:50 last edited by
        #3

        @raven-worx Thank you so much for the response. I will begin working on that and work with the caveat that you have mentioned! I appreciate your help! I will let you know the results.

        1 Reply Last reply
        0
        • R raven-worx
          19 Jul 2016, 13:39

          @HunterMetcalfe

          QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
          

          As starting point you can reimplement focusNextPrevChild(bool) method (which will be called when the focus should be set to the next/previous widget when TAB/BACKTAB is pressed).

          bool MyWidget::focusNextPrevChild( bool next )
          {
                 bool result = BaseClass::focusNextPrevChild( next );
                 if( result )
                 {
                      if( QWidget* widget = QApplication::focusWidget() )
                          QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
                 }
                 return result;
          }
          

          The caveat is that this has to be done for every widget type. Thus you may want to write this code into a macro (with base class parameter) instead?

          H Offline
          H Offline
          HunterMetcalfe
          wrote on 19 Jul 2016, 14:31 last edited by
          #4

          @raven-worx Quick question again. So I have a QWidget that is made up of other QWidgets. For BaseClass:: would that perhaps just be QWidget or would it be the Widget that contains that widget. (Sorry for the confusing language). I think this is what you were saying for the caveat.

          R 1 Reply Last reply 20 Jul 2016, 05:46
          0
          • R raven-worx
            19 Jul 2016, 13:39

            @HunterMetcalfe

            QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
            

            As starting point you can reimplement focusNextPrevChild(bool) method (which will be called when the focus should be set to the next/previous widget when TAB/BACKTAB is pressed).

            bool MyWidget::focusNextPrevChild( bool next )
            {
                   bool result = BaseClass::focusNextPrevChild( next );
                   if( result )
                   {
                        if( QWidget* widget = QApplication::focusWidget() )
                            QCursor::setPos( widget->mapToGlobal( widget->rect().center() ) );
                   }
                   return result;
            }
            

            The caveat is that this has to be done for every widget type. Thus you may want to write this code into a macro (with base class parameter) instead?

            H Offline
            H Offline
            HunterMetcalfe
            wrote on 19 Jul 2016, 14:43 last edited by
            #5

            @raven-worx This may be a noob question, but how do you paste a picture into this forum? I can send you a picture to elaborate more.

            M 1 Reply Last reply 19 Jul 2016, 18:50
            0
            • H HunterMetcalfe
              19 Jul 2016, 14:43

              @raven-worx This may be a noob question, but how do you paste a picture into this forum? I can send you a picture to elaborate more.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 19 Jul 2016, 18:50 last edited by
              #6

              @HunterMetcalfe said:

              • This may be a noob question, but how do you paste a picture
                Hi,
                you must upload to a site and get link to paste here.
                Forum dont allow directly :)
              1 Reply Last reply
              0
              • H HunterMetcalfe
                19 Jul 2016, 14:31

                @raven-worx Quick question again. So I have a QWidget that is made up of other QWidgets. For BaseClass:: would that perhaps just be QWidget or would it be the Widget that contains that widget. (Sorry for the confusing language). I think this is what you were saying for the caveat.

                R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 20 Jul 2016, 05:46 last edited by
                #7

                @HunterMetcalfe said:

                @raven-worx Quick question again. So I have a QWidget that is made up of other QWidgets. For BaseClass:: would that perhaps just be QWidget or would it be the Widget that contains that widget.

                What i meant is that you need to subclass every widget type and reimplement this method for every widget (and parent widget) you'd like to see this behavior.

                So if you only want it to happen for a certain container, every child widget of the container has to have this method reimplemented.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0

                5/7

                19 Jul 2016, 14:43

                • Login

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