Reputation: 535
I am currently creating a GUI for an application and I want to make it frameless and add the minimize and close buttons myself. What I want to achieve can be seen in this answer:
The window structure I want to achieve
Since the GUI structure that I have in mind is really complex I really need that I have to use Qt Designer. Is there a way to achieve what is done in the answer above in the Qt Designer?
Upvotes: 1
Views: 1656
Reputation: 1
In your UIfile.py
self.setWindowFlag(QtCore.Qt.WindowType.FramelessWindowHint).
Also, in your backend file you must create
QSizeGrip(some_obj)
where some_obj is any object (frame, dutton or etc) for expanding your window, write this inside init().
Also you must write in your backend file inside your Class this:
def move_window(e): # inside __init__()
"""Drag your window"""
if e.buttons() == QtCore.Qt.MouseButton.LeftButton:
try:
self.move(self.pos() + e.globalPosition().toPoint() - self.clickPosition)
self.clickPosition = e.globalPosition().toPoint()
e.accept()
except AttributeError:
pass
def mousePressEvent(self, e): # inside class
self.clickPosition = e.globalPosition().toPoint()
and
self.some_obj.mouseMoveEvent = move_window # inside __init__()
Written for PySide6, can be adapted for PyQt
Upvotes: 0
Reputation: 24420
One way to achieve this is to create your application window as usual in Qt Designer, load the .ui file in the python via uic.loadUi
and add it to the layout of box.contentWidget()
instead of the edit
in the linked example.
Upvotes: 1