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. How to move origin point of QGraphicsView to its Center?

How to move origin point of QGraphicsView to its Center?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k 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.
  • O Offline
    O Offline
    onurcevik
    wrote on last edited by
    #1

    Hello, I am trying to implement cartesian coordinate system on QGraphicsView. But unlike cartesian coordinate system, QGraphicsView's origin point starts at left top. I tried to move it to the center like this:

    QPoint MyGraphicsView::centerOriginPoint(QPoint clickedPoint)
    {
        QPoint originPoint(ORIGINX,ORIGINY); // ORIGINX: WIDTH/2 , ORIGINY: HEIGHT/2
        clickedPoint.setX(clickedPoint.x()-ORIGINX);
        clickedPoint.setY(ORIGINY-clickedPoint.y());
        return clickedPoint;
    }
    

    It works when I print clicked point on console. But whenever I need to add an item on QGraphicsScene I need to do re-add the values that I substracted. Is there a better way to do this? Can I somehow set QGraphicsView's or QGraphicsView's origin to its center without substracting or adding values? Please excuse my poor English.

    ODБOïO 1 Reply Last reply
    0
    • O onurcevik

      Hello, I am trying to implement cartesian coordinate system on QGraphicsView. But unlike cartesian coordinate system, QGraphicsView's origin point starts at left top. I tried to move it to the center like this:

      QPoint MyGraphicsView::centerOriginPoint(QPoint clickedPoint)
      {
          QPoint originPoint(ORIGINX,ORIGINY); // ORIGINX: WIDTH/2 , ORIGINY: HEIGHT/2
          clickedPoint.setX(clickedPoint.x()-ORIGINX);
          clickedPoint.setY(ORIGINY-clickedPoint.y());
          return clickedPoint;
      }
      

      It works when I print clicked point on console. But whenever I need to add an item on QGraphicsScene I need to do re-add the values that I substracted. Is there a better way to do this? Can I somehow set QGraphicsView's or QGraphicsView's origin to its center without substracting or adding values? Please excuse my poor English.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @onurcevik hi see this https://stackoverflow.com/questions/10443894/how-to-set-qgraphicsscene-view-to-a-specific-coordinate-system/10444511#10444511

      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