Bug report #21053

QgsMapMouseEvent misses overload in python API

Added by Benjamin Jakimow over 5 years ago. Updated over 5 years ago.

Status:Closed
Priority:Low
Assignee:-
Category:Any
Pull Request or Patch supplied:No

Description

Description

According to the API documentation, the QgsMapMouseEvent can be created using two different constructors https://qgis.org/pyqgis/master/gui/QgsMapMouseEvent.html.

However, the python API fails to call the second constructor defintion.

Test

from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.testing import start_app, unittest

start_app()

class TestQgsFeature(unittest.TestCase):

    def test_QgsMapMouseEvent(self):
        canvas = QgsMapCanvas()
        canvas.setFixedSize(300, 300)

        pos = QPointF(0.5 * canvas.width(), 0.5 * canvas.height())
        # this works
        mouseEvent = QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)

        qgsMouseEvent1 = QgsMapMouseEvent(canvas, mouseEvent)
        self.assertIsInstance(qgsMouseEvent1, QgsMapMouseEvent)

        # fails
        qgsMouseEvent2 = QgsMapMouseEvent(
            canvas,
            QEvent.MouseButtonPress,
            QPointF(0.5 * canvas.width(), 0.5 * canvas.height()),
            Qt.LeftButton,
            Qt.LeftButton,
            Qt.NoModifier)
        self.assertIsInstance(qgsMouseEvent2, QgsMapMouseEvent)

if __name__ == '__main__':
    unittest.main()

System

Windows 10 Education, 64-Bit
QGIS version 3.4.3-Madeira
QGIS code revision 2f64a3c4e7

History

#1 Updated by Nyall Dawson over 5 years ago

The error is:

QPointF(0.5 * canvas.width(), 0.5 * canvas.height())

this should be a QPoint, not QPointF.

#2 Updated by Benjamin Jakimow over 5 years ago

  • Status changed from Open to Closed

Thanks, your right, that was my fault.

Everything works right.

Also available in: Atom PDF