Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. put marker on a vector layer / map
Forum Update on Monday, May 27th 2025

put marker on a vector layer / map

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
1 Posts 1 Posters 205 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    korai
    wrote on last edited by
    #1

    I am designing a GUI using Qt and QGIS and showing maps (shapefiles - Vector layers) on the GUI. I want to put a marker on the vector layers when I click somewhere on the map. I could get coordinates when I click on the vector layer. I am using QLabel class for the marker. I am moving the marker according to coordinates. The logic and related part of the code is as following:

    mpClickPoint = new QgsMapToolEmitPoint(mpMapCanvas);
    connect(mpClickPoint, SIGNAL(canvasClicked(QgsPointXY,Qt::MouseButton)), this, SLOT(selectCoord(QgsPointXY)));
    
    void MainWindow::selectCoord(QgsPointXY point)
    {
    QLabel *marker = new QLabel(mpMapCanvas);
    marker->setPixmap(QPixmap(":/mapMarker.png"));
    marker->move(point.x(), point.y());
    marker->show();
    }
    

    The problem is, wherever I click on the map, the markers are put somewhere else and they are put so close to each other. As you can see in the image below, I clicked 10 times on different places and markers have been put in the area on the top left of the map. How can I put markers correctly? Or should I follow another way?

    The Output is like follows:
    2022-01-25_18-07.png

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved