I didn't see any signal/slot/function that could tell me whether a widget is selected by mouse? Is it possible to have such an function to tell me whether the current QWidget is selected? And How could I differentiate between "the current widget is selected" and "one of its child widget is selected?"
You can check focus on a widget using hasFocus()
function. focus
property holds whether the widget has keyboard input focus or not. You can also get the current widget of the application that has the focus using QApplication::focusWidget()
. You can get a pointer to the focused widget like:
QWidget * fw = qApp->focusWidget();
When the focused widget is changed QApplication::focusChanged(QWidget *old, QWidget *now)
signal is emitted.You can connect it to a slot in which you do what ever you like based on the focus change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With