Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Use of focusWidget()
QtWS25 Last Chance

[Solved] Use of focusWidget()

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.0k Views
  • 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    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
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @
      YourClass *focused_widget;

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

      (Z(:^

      1 Reply Last reply
      0
      • McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        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
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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
          0
          • McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by
            #5

            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
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved