我有一个QGraphicsView元素,它没有边框,标题等,我想在屏幕上四处移动。我已经实现了用鼠标移动它的功能,但是它并不平滑,它在跳跃并且没有正确跟随鼠标。
def mousePressEvent(self, event):
self.mouseMovePos = None
if event.button() == QtCore.Qt.LeftButton:
self.mouseMovePos = event.globalPos()
def mouseMoveEvent(self, event):
if event.buttons() == QtCore.Qt.LeftButton:
currPos = self.mapToGlobal(self.pos())
globalPos = event.globalPos()
diff = globalPos - self.mouseMovePos
newPos = self.mapFromGlobal(currPos + diff / 40)
self.move(newPos)
也许是因为性能?有没有一种方法可以使窗口平滑地跟随我的鼠标?