Qt: how to determine if a widget is selected?

I did not see any signals / slots / functions that could tell me if the widget is selected with the mouse? Is it possible for such a function to tell me if the current QWidget is selected? And how can I distinguish between "selected current widget" and "selected one of its child widget?"

+5
source share
1 answer

You can check the focus on widgets using the hasFocus() function. focus property whether the widget has keyboard focus or not. You can also get the current application widget with focus using QApplication::focusWidget() . You can get a pointer to a focused widget, for example:

 QWidget * fw = qApp->focusWidget(); 

When changing the focused widget, the signal QApplication::focusChanged(QWidget *old, QWidget *now) is issued. You can connect it to the slot in which you do what you like, depending on the change in focus.

+6
source

Source: https://habr.com/ru/post/1214462/


All Articles