When building custom GIS applications using the QGIS API and Qt, it’s often useful to show the current mouse coordinates on the map canvas. A common place to display this information is in the status bar.
In this post, we’ll look at a minimal example of how to connect the QGIS map canvas (QgsMapCanvas) to a status bar widget and display real-time coordinates.
Minimal Implementation
We only need to connect the xyCoordinates signal from the canvas to a slot that updates a QLineEdit (or any other text display widget):
void StatusBarCoordinatesWidget::setMapCanvas( QgsMapCanvas *mapCanvas )
{
if ( mMapCanvas )
{
disconnect( mMapCanvas, &QgsMapCanvas::xyCoordinates,
this, &StatusBarCoordinatesWidget::showMouseCoordinates );
}
mMapCanvas = mapCanvas;
connect( mMapCanvas, &QgsMapCanvas::xyCoordinates,
this, &StatusBarCoordinatesWidget::showMouseCoordinates );
}
void StatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &point )
{
if ( point.isEmpty() )
{
mLineEdit->clear();
return;
}
QString coordText = QgsCoordinateUtils::formatCoordinateForProject(
QgsProject::instance(),
point,
mMapCanvas->mapSettings().destinationCrs(),
static_cast<int>( mMousePrecisionDecimalPlaces ) );
mLineEdit->setText( coordText );
}
How It Works
setMapCanvas()
Connects theQgsMapCanvas::xyCoordinatessignal to our slot.showMouseCoordinates()
Directly receives the current mouse position (QgsPointXY) and updates the status bar with properly formatted coordinates.
That’s it — no extra member variables or methods needed.
Example Output
When the mouse moves across the map:
X: 77.5946 Y: 12.9716
These values update instantly in the status bar.
Conclusion
By directly connecting the QGIS map canvas signal to a status bar widget, we can create a clean and efficient coordinate display with very little code.
This pattern is also extendable — for example, you can:
- Add multiple coordinate formats (WGS84 + Project CRS).
- Allow copying coordinates with a right-click menu.
- Display additional context like elevation or map scale.
If you’re interested in a full-fledged GIS solution, check out our flagship product PrithviGIS – a powerful QGIS-based platform for real-time geospatial visualization.
For collaboration, demos, or project discussions, feel free to contact Manya Technologies.

