PyQt6更新了无框可拖动窗口



我还没有看到PyQt6的更新版本,所以我在这里发布代码片段

def center(self):
qr = self.frameGeometry()
cp = self.screen().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def mousePressEvent(self, event):
self.oldPos = event.position().toPoint()
def mouseMoveEvent(self, event):
delta = QPoint(event.position().toPoint() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())

def mouseReleaseEvent(self, event):
self.oldPos = event.position().toPoint()

您可以将更新后的代码用于PyQt6:

def center(self):
qr = self.frameGeometry()
cp = self.screen().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())

def mousePressEvent(self, event):
self.dragPos = event.globalPosition().toPoint()

def mouseMoveEvent(self, event):
self.move(self.pos() + event.globalPosition().toPoint() - self.dragPos )
self.dragPos = event.globalPosition().toPoint()
event.accept()

相关内容

  • 没有找到相关文章

最新更新