开发者

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

开发者 https://www.devze.com 2023-04-04 12:16 出处:网络
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 ch

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消