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. [Solved]QGraphicsItem
Forum Updated to NodeBB v4.3 + New Features

[Solved]QGraphicsItem

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.0k 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.
  • E Offline
    E Offline
    epalmero
    wrote on last edited by
    #1

    Dear All:

    I am trying to create an application that perform scientifics graphics and I have a question. In all the tutorial I listen that the QGraphicsItem coordinates system is a local coordinate system that is not in pixel coordinates. In my application I need to define a QGraphicsItem coordinate system that match the pixel coordinates system.

    This mean that if my QGraphicsItem has a size [30 60] I want to draw from 0 to 29 and 0 69 thinking that this are pixel in the screen.

    Best and thanks in advance
    Ernesto

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      Well, if you don't zoom the scene in or out with the QGraphicsView, then the default zoom level will have 1 unit = 1 pixel. For individual items, QGraphicsItem::ItemIgnoresTransformations will probably do what you want.

      Though, generally speaking you want to avoid counting pixels whenever possible. It can make it hard to move an application between different screens. (And in the case of things like retina displays, you need to deal with either very small pixels or "virtual" pixels and the definition of a pixel gets a bit vague.)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stevenceuppens
        wrote on last edited by
        #3

        Hey,

        Transformations
        The transformation matrix tranforms the scene into view coordinates. Using the default transformation, provided by the identity matrix,

        one pixel in the view represents one unit in the scene: matrix 1:1
        (e.g., a 10x10 rectangular item is drawn using 10x10 pixels in the view).

        If a 2x2 scaling matrix is applied, the scene will be drawn in 1:2
        (e.g., a 10x10 rectangular item is then drawn using 20x20 pixels in the view).

        So: 1pixel in the view == 1 pixel in the scene if scaling matrix is 1:1

        Coordinates
        QGraphicsView by default centers coordinate 0x0 in the center of the view. This means that if you draw a QGraphicsItem to the QGraphicsScene (with x=0, y=0) your item is centred..

        by calling
        @void QGraphicsView::setAlignment(Qt::AlignLeft | Qt::AlignTop)@

        Your item will be rendered in the top-left corner...

        Info
        You could compare
        a QGraphicsScene like a (tree) model
        a QGraphicsView like a (tree) view
        a QGraphicsItem like your (model) records

        Steven CEUPPENS
        Developer / Architect
        Mobile: +32 479 65 93 10

        1 Reply Last reply
        0
        • E Offline
          E Offline
          epalmero
          wrote on last edited by
          #4

          Thanks very much for your answer this really help a lot.

          Best
          Ernesto

          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