fancypants-l
fancypants-l

Reputation: 79

Native PyQt function that tells you what widget is at a given position?

I am building a footage library, where each thumbnail is a QIcon on a QPushButton. I'd like the thumbnails to advance a frame as the user middle-mouse-button scrolls on top of the QPushButton. The challenge is getting which widget is under the mouse at the time of scroll.

I'm getting the X and Y position of the wheel-scrolling event like this:

def wheelEvent(self, event):
        x = event.pos().x()
        y = event.pos().y()

So, is there is some native PyQt function I'm overlooking, like getWidgetAt(x,y) that I could use to figure out which QPushButton the user is hovering over?

Thank you for your advice!

Upvotes: 1

Views: 1284

Answers (1)

alexisdm
alexisdm

Reputation: 29896

You can get the widget with either

hoveredWidget = QApplication.widgetAt(event.globalPos())
# or  
hoveredWidget = self.childAt(event.pos())

But it would make more sense to subclass QPushButton to implement wheelEvent directly inside the target widget.

Upvotes: 2

Related Questions