美文网首页PYQT5学习与开发
PYQT5(2)MyScrollWidget拖放文件功能的实现

PYQT5(2)MyScrollWidget拖放文件功能的实现

作者: 弗兰克万岁 | 来源:发表于2018-12-07 16:54 被阅读104次
    class MyScrollWidget(QWidget):
        def __init__(self):
            super(QWidget, self).__init__()
            # self.resize(800, 600)
            self.move(0, 0)
            # self.setMouseTracking(False)
            self.last_time_move = 0
            self.last_time_move_x = 0
        def eventFilter(self,source, event):
            try:
                if event.type() == QEvent.MouseMove:
                    print(event.pos().y(),event.pos().x())
                    if self.last_time_move == 0:
                        self.last_time_move = event.pos().y()
                        self.last_time_move_x=event.pos().x()
                    distance = (self.last_time_move - event.pos().y())/100
                    distance_x = (self.last_time_move - event.pos().x())/100
                    self.scroll(distance_x,0)
                    self.last_time_move = event.pos().y()
                    self.last_time_move_x=event.pos().x()
                elif event.type() == QEvent.MouseButtonRelease:
                    self.last_time_move = 0
                    self.last_time_move_x = 0
                return QWidget.eventFilter(self, source, event)
            except Exception as e:
                print(e)
    #by the way 没能搞定y轴上的滚动,不过发现用滚轮也可以,就先放一放了,实现功能再回来优化
    

    相关文章

      网友评论

        本文标题:PYQT5(2)MyScrollWidget拖放文件功能的实现

        本文链接:https://www.haomeiwen.com/subject/mvxxhqtx.html