I am working under c++ with the qgis API 2.8

In order to make different operation on a canvas like personnalized rotation or selecting a region for zooming, I had to catch different signal like rightclick, leftclick, clicked or dblclick.

I saw in the API online the class QgsMapToolEmitPoint, Does anyone already used it ?


I found the solution A lot of post on stackexchange showme the way to do that

Here a sample extract of the code in c++ :

CMyQgsMapCanvas     * mpMapCanvas;
QgsMapToolEmitPoint         * mpClickPoint;

mpMapCanvas = new CMyQgsMapCanvas( this, NULL);

mpClickPoint = new QgsMapToolEmitPoint(mpMapCanvas);

connect(mpClickPoint ,SIGNAL(canvasClicked(QgsPoint,Qt::MouseButton)),this, SLOT(calcPoint(QgsPoint,Qt::MouseButton)));

// the slot
void MainWindow::calcPoint(QgsPoint pPoint,Qt::MouseButton pMouseBtn)
    qDebug() << "Mouse Click";

Now each you click on the canvas the slot was called. I think that mpClickPoint can be a QgsMapTool cause of inherit of classes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.