QGraphicsRectItem - mapToParent and mapFromParent
General and Desktop
4
Posts
2
Posters
4.4k
Views
1
Watching
-
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();}@
The result is:
QPointF(10, 10)
QPointF(10, 10)For me the result should be:
QPointF(110, 10)
QPointF(-110, 10):s
-
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() ?
-
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.