0

I am working under C++ with the QGIS API 2.8

In order to make different operation on a canvas like personalized 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 ?

1 Answer 1

1

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++ :

//Declaration
CMyQgsMapCanvas     * mpMapCanvas;
QgsMapToolEmitPoint         * mpClickPoint;

mpMapCanvas = new CMyQgsMapCanvas( this, NULL);
mpMapCanvas->create();
mpMapCanvas->setProjection();

mpClickPoint = new QgsMapToolEmitPoint(mpMapCanvas);
mpMapCanvas->setMapTool(mpClickPoint);

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 and acknowledge you have read our privacy policy.

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