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. Coordinate systems for QGrpahicsView/Scene and QPainter
Qt 6.11 is out! See what's new in the release blog

Coordinate systems for QGrpahicsView/Scene and QPainter

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 469 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.
  • J Offline
    J Offline
    jkwok678
    wrote on last edited by jkwok678
    #1

    Is there any difference?
    In my QPainter code I just did a drawImage(x,y,*image).

    QGrpahicsView.

    painter.setWindow(QRect(0, 0, canvasSizeX, canvasSizeY));
    painter.setViewport(0, 0, canvasSizeX, canvasSizeY);

    QGraphicsPixmapItem *straightPixmapItem = scene->addPixmap(*image);
    straightPixmapItem->setPos(x,y);

    But now when I do this, it never shows at the same location. Surely they should both output to the same location if the window size is the same?

    1 Reply Last reply
    0
    • eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      try:

      view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
      

      Note: don't abuse dynamic memory, you don't need a QPixmap pointer:

      void drawImage(qreal x, qreal y, const QPixmap & image){
         QGraphicsPixmapItem *straightPixmapItem = scene->addPixmap(image);
          straightPixmapItem->setPos(x,y); 
      }.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      1
      • J Offline
        J Offline
        jkwok678
        wrote on last edited by
        #3

        @eyllanesc said in Coordinate systems for QGrpahicsView/Scene and QPainter:

        view->setAlignment(Qt::AlignLeft | Qt::AlignTop);

        Thanks, it works, but what exactly is that command and what does it do?

        mrjjM 1 Reply Last reply
        0
        • J jkwok678

          @eyllanesc said in Coordinate systems for QGrpahicsView/Scene and QPainter:

          view->setAlignment(Qt::AlignLeft | Qt::AlignTop);

          Thanks, it works, but what exactly is that command and what does it do?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @jkwok678

          It tells how the view is "centered"

          https://doc.qt.io/qt-5/qgraphicsview.html#alignment-prop

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jkwok678
            wrote on last edited by
            #5
            This post is deleted!
            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