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轴上的滚动,不过发现用滚轮也可以,就先放一放了,实现功能再回来优化
网友评论