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. QTGraphicsItem relative coordinates in a Grid
QtWS25 Last Chance

QTGraphicsItem relative coordinates in a Grid

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtgraphicsitemqtgraphics
2 Posts 2 Posters 794 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.
  • Kyle MorrisK Offline
    Kyle MorrisK Offline
    Kyle Morris
    wrote on last edited by Kyle Morris
    #1

    I'm designing a grid system in a QgraphicsView. I've made Tiles using QGraphicsItems which lay across the view, as show below:
    image here
    The issue I'm having is when adding objects to a tile. I'm trying to add a QPixmapItem or some other item (such as a rectangle) to a specific tile, say (3,4) tile in the grid. What is the best way to do this, such that the item is drawn relative to a given tile.

    That is, if I were to say addObject(myObject, x, y) the object will be drawn to fit right in tile x, y, and I can scale it relative to that tile. I was able to make everything work for one grid size; but if I add rows/columns, everything is off center again.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      Make the respective tile the parentItem of your new GraphicsItem:

      myItem->setParentItem(myTile);

      Now all coordinates of myItem are relative to that respective tile.

      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