I want to call some functions when I click left and right on the canvas. I wrote the following code for this:
mpMapCanvas = new QgsMapCanvas();
mpClickPoint = new QgsMapToolEmitPoint(mpMapCanvas);
connect(mpClickPoint, SIGNAL(canvasClicked(QgsPointXY,Qt::MouseButton)), this, SLOT(selectCoord(QgsPointXY)));
This code works, but for both left and right mouse click. So there is no difference between them right now. Either left or right click is calling selectCoord() function. I want to separate them and make it work only when I click left. That's why I tried:
connect(mpClickPoint, SIGNAL(canvasPressEvent(QgsMapMouseEvent)), this, SLOT(mouseEvent(QgsMapMouseEvent)));
void MainWindow::mouseEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton){
qDebug() << "Left clicked" << '\n';
}
}
I don't know why it didn't work. Any idea?