[Solved] Use of focusWidget()
-
wrote on 17 Oct 2012, 09:06 last edited by
Hi
I am trying to find which of the buttons has the focus and do an animateClick() on it.
@QWidget *focused_widget;
focused_widget = QWidget::focusWidget();
focused_widget->animateClick(ANIMATE_CLICK_TIME);@..does not work and returns: 'class QWidget' has no member named 'animateClick'
Can I somehow casting the widget type or how do I solve this?Thanks
-
@
YourClass *focused_widget;focused_widget = q_object_cast<YourClass>(QWidget::focusWidget());
focused_widget->animateClick(ANIMATE_CLICK_TIME);
@ -
wrote on 17 Oct 2012, 09:32 last edited by
Seems not to be possible in assignment, so tried
@qobject_cast<AsButton>(focused_widget)->animateClick(ANIMATE_CLICK_TIME);@
.. still no luck ... I am still doing something wrong
-
Waaait, QWidget::focusWidget() is not a static method! You need to run it either on your top-level widget, or go with QApplication::focusWidget(). And of course, I forgot to add a pointer in my cast:
@
focused_widget = q_object_cast<YourClass *>(QWidget::focusWidget());
@ -
wrote on 17 Oct 2012, 10:01 last edited by
Thanks a lot.
Final solution which works perfect:@AsButton *focused_widget;
focused_widget = qobject_cast<AsButton *>(QApplication::focusWidget());
focused_widget->animateClick(ANIMATE_CLICK_TIME);@
1/5