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 hoveri开发者_如何学编程ng over?
Thank you for your advice!
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.
精彩评论