7

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.

bangKok
  • 332
  • 2
  • 13
  • The warning is telling you that the function may be removed in future versions and that there may be issues with how it works in current versions (prompting the deprecation). Have you checked the documentation to see what the suggested change it? It may be worth it to avoid your code just outright not working at some point when you upgrade. – Kemp May 27 '21 at 13:44
  • yes I checked it, but I didn't find a something, to clear this problem. but if its only a message, for the future, I will kepp an eye on it. Thanks for your answer – bangKok May 27 '21 at 13:46
  • It looks like `globalPos` has been replaced by `globalPosition`, which probably returns the position as a float instead of an int. – Kemp May 27 '21 at 14:33
  • Try with `globalPosition()`. And, as said, that's just a *warning*. – musicamante May 27 '21 at 14:36

2 Answers2

5

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
elena.kim
  • 930
  • 4
  • 12
  • 22
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)
Anonymous
  • 596
  • 1
  • 9
  • 26