#๐Ÿ”’ making a draggable frameless qdialog in pyqt6

10 messages ยท Page 1 of 1 (latest)

edgy peak
#

I am trying to making draggable frameless qdialog in pyqt6, but it doesnt work as intended.

    def _is_in_top_bar(self, pos):
        """Check if the click is within the top bar."""
        return 0 <= pos.y() <= 50  # Adjust based on top bar height

    def mousePressEvent(self, event):
        if event.button() == qt.MouseButton.LeftButton and self._is_in_top_bar(event.pos()):
            self._is_dragging = True
            self._drag_position = event.globalPosition().toPoint() - self.frameGeometry().topLeft()
            event.accept()

    def mouseMoveEvent(self, event):
        if self._is_dragging:
            self.move(event.globalPosition().toPoint() - self._drag_position)
            event.accept()

    def mouseReleaseEvent(self, event):
        if event.button() == qt.MouseButton.LeftButton:
            self._is_dragging = False
            event.accept()

what can I do?

rich rainBOT
#

@edgy peak

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

edgy peak
#

when I click the dialog nothing happen, i have made sure the events are being registered and they are

#

I have also tried to set qt.WidgetAttribute.WA_TransparentForMouseEvents to true, but it not changed anything

coral roost
edgy peak
#

it work now

#

!close

rich rainBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.