Pyside2 Qmainwindow无边框简单的移动事件
参考其他作者制作可行!感谢!
参考如下:
https://www.cnblogs.com/FanMLei/p/10501037.html
仿照QQ做了无登陆界面,奈何无法移动;
在浏览了N多帖子后发现了最简便的方法,适合初学者!
直接上代码:
一,仍然需要重写鼠标的移动事件;
class Mywindow(QMainWindow):
def __int__(self):
super().__init__()
def mousePressEvent(self, event): ##事件开始
if event.button() == QtCore.Qt.LeftButton:
self.Move = True ##设定bool为True
self.Point = event.globalPos() - self.pos() ##记录起始点坐标
event.accept()
def mouseMoveEvent(self, QMouseEvent): ##移动时间
if QtCore.Qt.LeftButton and self.Move: ##切记这里的条件不能写死,只要判断move和鼠标执行即可!
self.move(QMouseEvent.globalPos() - self.Point) ##移动到鼠标到达的坐标点!
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent): ##结束事件
self.Move = False
二,重写了mouse**Event函数,记得应用到QmainWindow;
class GUI():
def __init__(self):
self.window = Mywindow() ##记得要引用重写的函数,而不是QmainWindow()
图片结果:
新手上路,勿喷!
用最简单的方式,满足最想达到的目的!
感谢前车之鉴!