QGraphicsRectItem - mapToParent and mapFromParent

  • 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;

    QGraphicsView view(&scene);
    scene.setBackgroundBrush(QBrush(Qt::black, Qt::SolidPattern));
    view.setStyleSheet( "QGraphicsView { border-style: none; }" );
    QGraphicsRectItem *item1 = new QGraphicsRectItem(100,0,200,200);
    QGraphicsRectItem *item2 = new QGraphicsRectItem(0,0,100,100,item1);
    item1->setBrush(QBrush(Qt::gray, Qt::SolidPattern));
    item2->setBrush(QBrush(Qt::red, Qt::SolidPattern));
    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)


  • 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() ?

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

  • 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.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.