Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [Solved] Use of focusWidget()

    General and Desktop
    2
    5
    2706
    Loading More Posts
    • 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.
    • McLion
      McLion 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

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        @
        YourClass *focused_widget;

        focused_widget = q_object_cast<YourClass>(QWidget::focusWidget());
        focused_widget->animateClick(ANIMATE_CLICK_TIME);
        @

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • McLion
          McLion 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

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            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());
            @

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • McLion
              McLion 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 Reply Last reply Reply Quote 0
              • First post
                Last post