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



  • Hey!

    How can I get an item from under the mouse?

    TIA



  • 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 ?


  • Moderators

    @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?



  • 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 :- )



  • Ok found a better way heh.

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

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.