I'm developing in Qt with C++. I have displayed a map and want to be able to register when the mouse clicks on a location on the map. in my class .cpp file I have tried including the mouseClicked(QMouseEvent *event), but this is never called when I click.
Display_a_map.cpp
void Display_a_map::mouseClicked(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
qDebug() << "testing";
}
}
Solved! Go to Solution.
Hi John,
In QtWidgets, the name of event functions are "mouseXxxEvent": https://doc.qt.io/qt-5/qgraphicsview.html#mousePressEvent.
"mouseClicked" is a signal provided by map and scene views, not an event handler: https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-mapgraphicsview.html
You can use it like every signals:
Dispay_a_map::Dispay_a_map()
{
connect(this, &Dispay_a_map::mouseClicked,
this, &Dispay_a_map::handleMouseClicked);
}
// defined as slot
void Display_a_map::handleMouseClicked(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
qDebug() << "testing";
}
}
Hi John,
In QtWidgets, the name of event functions are "mouseXxxEvent": https://doc.qt.io/qt-5/qgraphicsview.html#mousePressEvent.
"mouseClicked" is a signal provided by map and scene views, not an event handler: https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-mapgraphicsview.html
You can use it like every signals:
Dispay_a_map::Dispay_a_map()
{
connect(this, &Dispay_a_map::mouseClicked,
this, &Dispay_a_map::handleMouseClicked);
}
// defined as slot
void Display_a_map::handleMouseClicked(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
qDebug() << "testing";
}
}
Ahhh. That makes a lot of sense. Thanks