<small id='NYR1r'></small><noframes id='NYR1r'>

<legend id='NYR1r'><style id='NYR1r'><dir id='NYR1r'><q id='NYR1r'></q></dir></style></legend>

        <bdo id='NYR1r'></bdo><ul id='NYR1r'></ul>
    1. <tfoot id='NYR1r'></tfoot>

      1. <i id='NYR1r'><tr id='NYR1r'><dt id='NYR1r'><q id='NYR1r'><span id='NYR1r'><b id='NYR1r'><form id='NYR1r'><ins id='NYR1r'></ins><ul id='NYR1r'></ul><sub id='NYR1r'></sub></form><legend id='NYR1r'></legend><bdo id='NYR1r'><pre id='NYR1r'><center id='NYR1r'></center></pre></bdo></b><th id='NYR1r'></th></span></q></dt></tr></i><div id='NYR1r'><tfoot id='NYR1r'></tfoot><dl id='NYR1r'><fieldset id='NYR1r'></fieldset></dl></div>
      2. QMouseEvent' 对象没有属性 'pos'

        时间:2023-08-04

            <small id='p9DoD'></small><noframes id='p9DoD'>

              <tbody id='p9DoD'></tbody>
            <tfoot id='p9DoD'></tfoot>
                <legend id='p9DoD'><style id='p9DoD'><dir id='p9DoD'><q id='p9DoD'></q></dir></style></legend>

                  <bdo id='p9DoD'></bdo><ul id='p9DoD'></ul>

                • <i id='p9DoD'><tr id='p9DoD'><dt id='p9DoD'><q id='p9DoD'><span id='p9DoD'><b id='p9DoD'><form id='p9DoD'><ins id='p9DoD'></ins><ul id='p9DoD'></ul><sub id='p9DoD'></sub></form><legend id='p9DoD'></legend><bdo id='p9DoD'><pre id='p9DoD'><center id='p9DoD'></center></pre></bdo></b><th id='p9DoD'></th></span></q></dt></tr></i><div id='p9DoD'><tfoot id='p9DoD'></tfoot><dl id='p9DoD'><fieldset id='p9DoD'></fieldset></dl></div>
                  本文介绍了QMouseEvent' 对象没有属性 'pos'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当我尝试将图像标签移动到屏幕上时,我在使用 PyQT6 时遇到了一些问题.

                  I'm having some problems here with PyQT6 while i try to move a image label trought the screen.

                  我试图将 Scrollabel 区域中的标签移动到框架中,但出现以下错误:PyQT6: 'QMouseEvent' object has no attribute 'pos'"

                  I'm trying to move a label that is in a Scrollabel Area to a frame, and i get the following error: "PyQT6: 'QMouseEvent' object has no attribute 'pos' "

                  代码如下:

                  class DraggableLabel(QLabel):
                      def init(self, parent, image):
                          super(QLabel, self).init(parent)
                          pixmap = QPixmap(image)
                          pixmap = pixmap.scaled(120, 120)
                  
                          self.setPixmap(pixmap)
                          # self.show()
                  
                      def mousePressEvent(self, event):
                          if event.button() == Qt.MouseButtons.LeftButton:
                              # print('Evento: ', event.screenPos())
                              self.drag_start_position = event.pos()
                  
                      def mouseMoveEvent(self, event):
                          if not (event.buttons() & Qt.MouseButtons.LeftButton):
                              return
                          if (event.pos() - self.drag_startposition).manhattanLength() < QApplication.startDragDistance():
                              return
                  
                          drag = QDrag(self)
                          mimedata = QMimeData()
                          mimedata.setText(self.text())
                          mimedata.setImageData(self.pixmap().toImage())
                  
                          drag.setMimeData(mimedata)
                          pixmap = QPixmap(self.size())
                          painter = QPainter(pixmap)
                          painter.drawPixmap(self.rect(), self.grab())
                          painter.end()
                          drag.setPixmap(pixmap)
                          drag.setHotSpot(event.pos())
                          drag.exec(Qt.CopyAction | Qt.MoveAction)
                  

                  编辑

                  追溯:

                  PS C:UsersdougProjetos> & C:/Python/python.exe c:/Users/doug/Projetos/main.py
                  qt.gui.imageio: libpng warning: iCCP: known incorrect sRGB profile
                  Traceback (most recent call last):
                    File "c:Usersdoug_Projetoslibsys_functions.py", line 25, in mousePressEvent
                      self.drag_start_position = event.pos()
                  AttributeError: 'QMouseEvent' object has no attribute 'pos'
                  

                  推荐答案

                  Qt6 重构了事件输入 API 以适应新技术(阅读 https://www.qt.io/blog/input-events-in-qt-6 了解更多信息)所以它引入了新的基础诸如 QSinglePointEvent 之类的 QMouseEvent 继承自的类具有返回事件位置(在本例中为鼠标)的 position() 方法.即便如此,Qt6 有 pos() 方法是多余的,但为了兼容性而维护,但似乎 PyQt6 已经消除了它,这似乎是一个错误,因为 PySide6 仍然保持它与 Qt6 的兼容性.所以在这种情况下,你应该使用 position() 而不是 pos().

                  Qt6 has refactored the event inputs API to adapt to new technologies (read https://www.qt.io/blog/input-events-in-qt-6 for more information) so it has introduced new base classes such as QSinglePointEvent from which QMouseEvent inherits that have the position() method that returns the position of the event (in this case the mouse). Even so, Qt6 has the pos() method that is redundant but is maintained for compatibility but it seems that PyQt6 has eliminated it which seems like a bug since PySide6 still maintains it having compatibility with Qt6. So in this case you should use position() instead of pos().

                  这篇关于QMouseEvent' 对象没有属性 'pos'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 PyQT5 对话窗口中记录按下的组合键 下一篇:Qthread中的Python访问父类的小部件

                  相关文章

                  最新文章

                  <tfoot id='doptm'></tfoot>
                    <bdo id='doptm'></bdo><ul id='doptm'></ul>

                  1. <small id='doptm'></small><noframes id='doptm'>

                    1. <legend id='doptm'><style id='doptm'><dir id='doptm'><q id='doptm'></q></dir></style></legend>

                    2. <i id='doptm'><tr id='doptm'><dt id='doptm'><q id='doptm'><span id='doptm'><b id='doptm'><form id='doptm'><ins id='doptm'></ins><ul id='doptm'></ul><sub id='doptm'></sub></form><legend id='doptm'></legend><bdo id='doptm'><pre id='doptm'><center id='doptm'></center></pre></bdo></b><th id='doptm'></th></span></q></dt></tr></i><div id='doptm'><tfoot id='doptm'></tfoot><dl id='doptm'><fieldset id='doptm'></fieldset></dl></div>