Trouble detecting mouseClick event

1114
2
Jump to solution
06-09-2021 03:40 PM
johnmarker
New Contributor III

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";
    }
}

 

0 Kudos
1 Solution

Accepted Solutions
GuillaumeBelz
Esri Contributor

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";
    }
}

 

View solution in original post

2 Replies
GuillaumeBelz
Esri Contributor

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";
    }
}

 

johnmarker
New Contributor III

Ahhh. That makes a lot of sense. Thanks

0 Kudos