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. Buggy behaviour of setPos of QGraphicsSimpleTextItem
Forum Updated to NodeBB v4.3 + New Features

Buggy behaviour of setPos of QGraphicsSimpleTextItem

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

    I have a zoom button(QGraphicsRectItem) which has two QGraphicsSimpleTextItem (+,-) as children. When i call setPos on text items coordinates are always set in scene's coordinates despite the fact that text items have parent(zoom button).

    This behaviour is against the documentation:

    "Child coordinates are relative to the parent's coordinates. If the child is untransformed, the difference between a child coordinate and a parent coordinate is the same as the distance between the items in parent coordinates. For example: If an untransformed child item is positioned precisely in its parent's center point, then the two items' coordinate systems will be identical. If the child's position is (10, 0), however, the child's (0, 10) point will correspond to its parent's (10, 10) point.Because items' position and transformation are relative to the parent, child items' coordinates are unaffected by the parent's transformation, although the parent's transformation implicitly transforms the child"

    @
    ZoomButton::ZoomButton(GeoMap * map,QGraphicsItem * parent):QGraphicsRectItem(parent) {
    this->map = map;
    setPen(QPen(QColor(255,255,255)));
    setBrush(QBrush(QColor(0,0,0,150)));
    // plusText = new QGraphicsTextItem()
    plusText = new QGraphicsSimpleTextItem(this);
    minusText = new QGraphicsSimpleTextItem(this);
    plusText->setText("+");
    minusText->setText("-");
    plusText->setPen(QPen(QColor(255,255,255)));
    plusText->setBrush(QBrush(QColor(255,255,255)));
    minusText->setBrush(plusText->brush());
    minusText->setPen(plusText->pen());
    QFont f;
    f.setFamily("Arial");
    f.setFixedPitch(true);
    f.setPixelSize(40);
    plusText->setFont(f);
    minusText->setFont(f);

    plusText->setPos(0,0); // it's just for this sample
    minusText->setPos(40,0);
    }

    @

    @
    QGraphicsScene * sc = new QGraphicsScene();
    zoomButton = new ZoomButton(map);
    zoomButton->setRect(100,100,200,70);
    sc->addItem(zoomButton);
    sc->setBackgroundBrush(QBrush(QColor(30,100,100)));
    view = new QGraphicsView(sc,0);
    view->setSceneRect(0,0,1000,1000);

    @

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joonhwan
      wrote on last edited by
      #2

      Did you consider the origin of your 'ZoomButton' object is (200,135) (center of rect) (not (100,100) which is top left) in scene corrdinate? In my case, the actual origin has been always easily misunderstood by myself. :-(

      joonhwan at gmail dot com

      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