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. QGraphicsRectItem - mapToParent and mapFromParent
Forum Updated to NodeBB v4.3 + New Features

QGraphicsRectItem - mapToParent and mapFromParent

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

    I'm confused about that functions :s
    @
    #include <QApplication>
    #include <QGraphicsView>
    #include <QDebug>
    #include <QGraphicsRectItem>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    QGraphicsScene scene;

    scene.setSceneRect(0,0,400,600);
    
    QGraphicsView view(&scene);
    
    scene.setBackgroundBrush(QBrush(Qt::black, Qt::SolidPattern));
    
    view.setFixedSize(400,600);
    view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view.setStyleSheet( "QGraphicsView { border-style: none; }" );
    
    QGraphicsRectItem *item1 = new QGraphicsRectItem(100,0,200,200);
    scene.addItem(item1);
    
    QGraphicsRectItem *item2 = new QGraphicsRectItem(0,0,100,100,item1);
    
    qDebug()<<item2->mapToParent(10,10);
    qDebug()<<item2->mapFromParent(10,10);
    
    item1->setBrush(QBrush(Qt::gray, Qt::SolidPattern));
    item2->setBrush(QBrush(Qt::red, Qt::SolidPattern));
    
    view.showFullScreen();
    
    return app.exec&#40;&#41;;
    

    }@

    The result is:
    QPointF(10, 10)
    QPointF(10, 10)

    For me the result should be:
    QPointF(110, 10)
    QPointF(-110, 10)

    :s

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Yes, all your scene, item1, and item2 are in the same a coordinate system, so the value should be the same.

      Perhaps what you want is setPos() ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        metRo_
        wrote on last edited by
        #3

        All i want is that 0,0 of item2 is 100,100 of scene (0,0 of item1)

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on last edited by
          #4

          If you want a point has two different coordinate values, you will need two different coordinate system, isn't it? One of easiest ways to do this is making their origin point at different position, that is why setPos() exists.

          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