Move Mouse when tab clicked on keyboard
-
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!
-
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?
-
@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.
-
@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.
-
@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.
-
@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 :)
- This may be a noob question, but how do you paste a picture
-
@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.