当前位置: 代码迷 >> 综合 >> PyQt5 自定义可拖动标题栏
  详细解决方案

PyQt5 自定义可拖动标题栏

热度:76   发布时间:2023-11-10 13:55:07.0

PyQt5 自定义可拖动标题栏

将此段代码加入到我的上一篇博客TitleWidget类中即可 实现标题栏的拖动

    def getRestoreInfo(self):return self.restorePos, self.restoreSizedef mousePressEvent(self, QMouseEvent):self.isPressed = Trueself.startMovePos = QMouseEvent.globalPos()print(self.startMovePos)def mouseMoveEvent(self, QMouseEvent):if self.isPressed:movePoint = QMouseEvent.globalPos() - self.startMovePoswidgetPos = self.parentWidget().parentWidget().pos()self.startMovePos = QMouseEvent.globalPos()self.parentWidget().parentWidget().move(widgetPos.x() + movePoint.x(), widgetPos.y() + movePoint.y())def mouseReleaseEvent(self, QMouseEvent):self.isPressed = False