Dragable pyqt frameless app
Unsolved
Qt for Python
-
Morning.
I have built an app with Qdesigner, with pyuic I created python code and made the app frameless. I added a qframe as a title bar which contains two qlabels, for icon and app info, and I added two qtoolbuttons for minimizing and close app. I need this bar title let me to move the app.
How's that Possible?
thank you very much
-
@arkero24 Take a look at https://doc.qt.io/qt-5/qwidget.html#mouseMoveEvent
You will need to store last mouse cursor position, then next time mouseMoveEvent is called you calculate mouse cursor position difference (current - last) and apply this difference to move your window. -
Here's a draggable frameless widget that might be a useful starting point for you. It uses mouseMoveEvent() to move itself when dragged.
class Marker(W.QWidget): def __init__(self, parent = None): W.QWidget.__init__(self, parent) self.setWindowFlags(QtCore.Qt.Widget | QtCore.Qt.FramelessWindowHint); self.setAttribute(QtCore.Qt.WA_NoSystemBackground, True); self.setAttribute(QtCore.Qt.WA_TranslucentBackground, True); self.clicked = False def paintEvent(self, ev): p = Gui.QPainter(self) p.fillRect(self.rect(), Gui.QColor(128, 128, 128, 128)) def mousePressEvent(self, ev): self.old_pos = ev.screenPos() def mouseMoveEvent(self, ev): if self.clicked: dx = self.old_pos.x() - ev.screenPos().x() dy = self.old_pos.y() - ev.screenPos().y() self.move(self.pos().x() - dx, self.pos().y() - dy) self.old_pos = ev.screenPos() self.clicked = True return W.QWidget.mouseMoveEvent(self, ev)