python - 弃用警告 : Function when moving app (removed titlebar) - PySide6

标签 python pyside

当我移动应用程序时,我收到此警告:

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()
我使用了这个代码:
        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()
有没有办法跳过这个警告?它有效,但这个警告很烦人。

最佳答案

这对我有用:

p = event.globalPosition()
globalPos = p.toPoint()
例如,您可以像这样使用:
def mousePressEvent(self, event):
    p = event.globalPosition()
    globalPos = p.toPoint()
    self.dragPos = globalPos

关于python - 弃用警告 : Function when moving app (removed titlebar) - PySide6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67723421/

相关文章:

python - 从文本文件中选择特定的信息并将它们转换为 python 中的数组/列表

python - Pyside 程序响应复选框单击而锁定

python - Pyside 中的 Matplotlib 与 Qt 设计器 (PySide)

python - PySide Phonon 错误,后端插件无法加载

python - tkinter 字体中没有属性 "call"错误

python - 格式化字符串 (%s) 返回 TypeError : a float is required

python - BytesIO 流到 Numpy 数组? (摄影机)

python - 如何从 PySide 中可能继承的 QLabel 样式中删除阴影?

python - QT python连接传递参数给函数

python - Python if 语句是否隐式地将 bool 应用于条件中找到的对象?