'DeprecationWarning: Function when moving app (removed titlebar) - PySide6

I get when I move the App this Warning:

C:\Qt\Login_Test\main.py:48: DeprecationWarning: Function: 'globalPos() const' is marked as deprecated, please check the documentation for more information.
  self.dragPos = event.globalPos()
C:\Qt\Login_Test\main.py:43: DeprecationWarning: Function: 'globalPos() const' is marked as deprecated, please check the documentation for more information.
  self.move(self.pos() + event.globalPos() - self.dragPos)
C:\Qt\Login_Test\main.py:44: DeprecationWarning: Function: 'globalPos() const' is marked as deprecated, please check the documentation for more information.
  self.dragPos = event.globalPos()

I used this code:

        self.remove_title()
        self.ui.appname_label.mouseMoveEvent = self.move_window

    def remove_title(self):
        self.setWindowFlag(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)

        self.shadow = QGraphicsDropShadowEffect(self)
        self.shadow.setBlurRadius(20)
        self.shadow.setXOffset(0)
        self.shadow.setYOffset(0)
        self.shadow.setColor(QColor(0, 0, 0, 250))

        self.ui.frame.setGraphicsEffect(self.shadow)

    def move_window(self, event):
        if event.buttons() == Qt.LeftButton:
            self.move(self.pos() + event.globalPos() - self.dragPos)
            self.dragPos = event.globalPos()
            event.accept()

    def mousePressEvent(self, event):
        self.dragPos = event.globalPos()

Is there a way to skip this warning? It works but this warning is annoying.



Solution 1:[1]

This works for me:

p = event.globalPosition()
globalPos = p.toPoint()

For example, you can use like this:

def mousePressEvent(self, event):
    p = event.globalPosition()
    globalPos = p.toPoint()
    self.dragPos = globalPos

Solution 2:[2]

event.pos() is deprecated and it may be removed in future versions.
Try using event.scenePosition() to avoid shakiness.

def mousePressEvent(self, event):
    if event.button() == Qt.LeftButton:
        self.offset = QPoint(event.position().x(),event.position().y())
    else:
        super().mousePressEvent(event)

def mouseMoveEvent(self, event):
    if self.offset is not None and event.buttons() == Qt.LeftButton:

        self.move(self.pos() + QPoint(event.scenePosition().x(),event.scenePosition().y()) - self.offset)
    else:
        super().mouseMoveEvent(event)

def mouseReleaseEvent(self, event):
    self.offset = None
    super().mouseReleaseEvent(event)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 elena.kim
Solution 2 Anonymous