Qt Forum

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

    Solved QToolBar - itemAt(event->pos()) ?

    General and Desktop
    2
    5
    478
    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.
    • D
      Dariusz last edited by

      Hey!

      How can I get an item from under the mouse?

      TIA

      jsulm 1 Reply Last reply Reply Quote 0
      • D
        Dariusz last edited by

        for (auto &item:actions()) {
                        QWidget *wid = widgetForAction(item);
                        QRect r = wid->rect();
                        r.moveTo(wid->pos());
                        qDebug() << r.contains(event->pos());
                    }
        

        This seems to be working... feels a bit "odd" tho ?

        1 Reply Last reply Reply Quote 0
        • jsulm
          jsulm Lifetime Qt Champion @Dariusz last edited by

          @Dariusz Can you explain better what you mean?
          "QToolBar - itemAt(event->pos()) ?" - what does this mean? You click on QToolBar and want to know which item is under the mouse cursor? Wouldn't that be the QToolButton you clicked?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • D
            Dariusz last edited by

            Yep. I was implementing drag/drop function to drop an item at a specific place and I needed an underlying item to paint drop indicator. All done now, I used the above loop to determine what item I had beneath. However, if you have another idea about getting the item from under the mouse let me know :- )

            1 Reply Last reply Reply Quote 0
            • D
              Dariusz last edited by

              Ok found a better way heh.

              QWidget *widgetPTr = widgetForAction(actionAt(event->pos()));
              
              

              :- ) QtoolBar has actionAt instead of itemAt :- )

              1 Reply Last reply Reply Quote 1
              • First post
                Last post