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. QGraphicsLineItem line is not at the center of the item
Forum Updated to NodeBB v4.3 + New Features

QGraphicsLineItem line is not at the center of the item

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

    I am drawing a QGraphicsLineItem line at the middle of the scene in QGraphicsView .But the lines doesn't appear at the (0,0) It has an offset of 5 pixels from the center on X axis.How do I align the line to be at it's bounds center?

    Here is my code:

    @

    QGraphicsLineItem *scrubber = new QGraphicsLineItem(0,0,0,100);

    scrubber->setPen(QPen(QColor(255,0,0,255)));
    gview->scene()->addItem(scrubber);

    scrubber->setPos(0.0f,0);

    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msue
      wrote on last edited by
      #2

      Possible reasons:
      a) x=0 is not in the center of the graphics scene's sceneRect. You may e.g. have an additional horizontal line from x=-5 to x=15 units.
      b) the graphics scene is not displayed in the center of the graphics view.
      c) the graphics view is displayed with a margin.

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

        Thanks.But how do I check these things?

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

          First, check the QGraphicsView's alignment property.
          Then, read the sceneRect of the QGraphicsScene. If you only added the one line, it should be exactly big enough to hold that line.

          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