I've build a simple app layout with QtDesigner
pyside6-designer
Then i saved the .ui file and converted to python code:
pyuic6 -x simpleApp.ui -o simpleApp.py
At this point i decided to make the window Frameless and Draggable.
So i've write this line and it works:
Form.setWindowFlags(QtCore.Qt.WindowType.FramelessWindowHint)
Then i added this two functions to work with the Mouse Events:
def mousePressEvent(self, event):
self.dragPos = event.globalPosition().toPoint()
def mouseMoveEvent(self, event):
Form.move(Form.pos() + event.globalPosition().toPoint() - self.dragPos)
self.dragPos = event.globalPosition().toPoint()
event.accept()
Now the issue is that the Frameless line works, instaed the 2 functions for drag the window dosen't works. I searched also online some solution but nothing seems usefull. Any advice?
Here's the complete runnable code:
# Form implementation generated from reading ui file 'simpleApp.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(320, 300)
Form.setWindowFlags(QtCore.Qt.WindowType.FramelessWindowHint) # <--- This line make Frameless Window
self.label = QtWidgets.QLabel(parent=Form)
self.label.setGeometry(QtCore.QRect(120, 70, 81, 16))
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(parent=Form)
self.pushButton.setGeometry(QtCore.QRect(110, 120, 75, 24))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "Im a Label"))
self.pushButton.setText(_translate("Form", "PushButton"))
def mousePressEvent(self, event): # First Function
self.dragPos = event.globalPosition().toPoint()
def mouseMoveEvent(self, event): # Second Function
Form.move(Form.pos() + event.globalPosition().toPoint() - self.dragPos)
self.dragPos = event.globalPosition().toPoint()
event.accept()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec())