Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qpixmap transform problem
Forum Updated to NodeBB v4.3 + New Features

Qpixmap transform problem

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 548 Views 1 Watching
  • 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 korai
    #1

    I am trying to translate QPixmap object (an icon) using methods of QPainter class. Related code is:

        marker = new QLabel(mpMapCanvas);
        QPixmap pixmap = QPixmap(":/mapMarker.png");
        marker->move(50,50);
    
        QSize size = pixmap.size();
        QPixmap pixmapc = pixmap;
    
        pixmapc.fill(QColor::fromRgb(100, 100, 100, 100));  // gray area, for visualization
        painter = new QPainter(&pixmapc);
        QTransform transform;
        transform.translate(-size.width()/2, 0);
        painter->setTransform(transform);
        painter->drawPixmap(0,0, pixmap);
        marker->setPixmap(pixmapc);
        marker->show();
    

    before translation:
    before.png

    after translation:
    after.png

    I tried to scale the gray area to prevent the cutting effect but it grows towards to bottom-right:
    scale.png

    How can I scale towards to top left to prevent the cutting? I think I need to to change the place of the origin and perform translation using the new origin. How can I do that? Or is there another way to prevent this cutting effect?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You only do a translation but not scale. What exactly are you trying to do?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      K 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        You only do a translation but not scale. What exactly are you trying to do?

        K Offline
        K Offline
        korai
        wrote on last edited by korai
        #3

        @Christian-Ehrlicher
        Sorry if my question was not clear.

        I am trying to put a marker on a map. When I click, I can put the marker, but I want to match the bottom tip of the marker/icon with the place where I click. Now the most top left of the icon image (24x24) matches with where I click. In the following figure, the center of the black plus (mouse pointer) indicates where I click :

        288bbd7d-6820-4440-9880-0f35d7981282.png

        I want to match the bottom tip of the icon with the center of this black plus, basically. But when I translate it to there, the icon becomes invisible, i.e. it is completely cut/lost.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mchinand
          wrote on last edited by
          #4

          In your case, I think you want to move your whole QLabel by -width/2,-height; the QLabel's pixmap is fine as it is in the original screenshot. Not sure if you will need to do any coordinate transformations to position it exactly how you want. QGraphicsScene/QGraphicsView may be a better option too depending on what you are needing to display and manipulate.

          K 2 Replies Last reply
          0
          • M mchinand

            In your case, I think you want to move your whole QLabel by -width/2,-height; the QLabel's pixmap is fine as it is in the original screenshot. Not sure if you will need to do any coordinate transformations to position it exactly how you want. QGraphicsScene/QGraphicsView may be a better option too depending on what you are needing to display and manipulate.

            K Offline
            K Offline
            korai
            wrote on last edited by
            #5

            @mchinand
            Exactly, I want to move the whole label whose size is 24x24 by -width/2,-height, but it somehow moves only the icon and keeps the frame (gray area).

            My purpose is to mark a specific coordinate (lat, lon). When I click on a point on the map, I can take the corresponding coordinate, and I want to put a marker there. I also thought to add the marker as an attribute but could not manage it...

            1 Reply Last reply
            0
            • M mchinand

              In your case, I think you want to move your whole QLabel by -width/2,-height; the QLabel's pixmap is fine as it is in the original screenshot. Not sure if you will need to do any coordinate transformations to position it exactly how you want. QGraphicsScene/QGraphicsView may be a better option too depending on what you are needing to display and manipulate.

              K Offline
              K Offline
              korai
              wrote on last edited by
              #6

              Hi @mchinand, sorry to bother you, but I want to ask a follow-up question. I could manage that problem by using QGraphicsScene/QGraphicsView. Thank you for the suggestion.

              When zooming in, zooming out or panning the map, the QGraphicsPixmapItem item is shifting, although I set its position already. I called the flag ItemIgnoresTransformations, but it didn't work. Do you have a recommendation for this?

              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