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. Where is the origin for QGraphicsPixmapItem in its own system?

Where is the origin for QGraphicsPixmapItem in its own system?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 530 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.
  • 4 Offline
    4 Offline
    414d
    wrote on last edited by
    #1

    The question is asked for QGraphicsPixmapItem, but as I understand it, it is suitable for all classes that inherit QGraphicsItem. I know that the origin is in (0, 0) of the QGraphicsPixmapItem's coordinate system. I read about Item Coordinates. I did the following tests that led to this question.

    • Adding a square's image from a file, no conversion
    QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s));
    
    

    Result:
    0_1548619798737_t1-1.jpg

    • Adding a square's image from a file, 45 degree rotation
    QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s));
    i->setRotation(45);
    

    Result:
    0_1548619945376_t2-1.jpg
    It is not visible here, but when the program was started, the square rotated about its center on QGraphicsView.

    • Adding two images of a square, rotation of the second square by 45 degrees
    QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s));
    QGraphicsPixmapItem* i1 = scene.addPixmap(QPixmap(s));
    i1->setRotation(45);
    

    Result:
    0_1548620159809_t3-1.jpg
    Here you can see that the first square is shifted to the right, the second square is turned relative to its upper left vertex.

    • Adding two images of a square, rotation of the first square by -45 degrees, rotation of the second square by 45 degrees
    QGraphicsPixmapItem* i = scene.addPixmap(QPixmap(s));
    QGraphicsPixmapItem* i1 = scene.addPixmap(QPixmap(s));
    i->setRotation(-45);
    i1->setRotation(45);
    

    Result:
    0_1548620672461_t4-1.jpg
    Here you can see that the first square also is turned relative to its upper left vertex.

    The question is: where is the origin of the QGraphicsItem's system relative to the rectangle which bounds this item? Personally, I thought that (0, 0) is in the center of this rectangle. Why in the 2nd case the square turned around its center, and in the 3rd and 4th cases relative to its upper left vertex?
    I know how to put the origin of a QGraphicsItem's coordinate system at a given point (to the center in this sample):

    i->setTransformOriginPoint(i->boundingRect().center());
    

    I don't understand the default behavior. To make correct transformation should I set the origin for QGraphicsItem's system when I creating it?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Isn't what you are looking for described here ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

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