Qt nested QGraphicsItem coordinates -


i expect, documentation, snippet

mainwindow::mainwindow(qwidget *parent)     : qmainwindow(parent) {     qgraphicsview *v = new qgraphicsview(new qgraphicsscene);     setcentralwidget(v);      qgraphicsrectitem *r1 = v->scene()->addrect(qrectf(100,100, 200,200), qpen(), qbrush(qt::red));     qgraphicsrectitem *r2 = new qgraphicsrectitem(r1);     r2->setrect(qrectf(10,10, 50,50));     r2->setbrush(qbrush(qt::blue)); } 

would draw blue rect inside red one, instead here result:

enter image description here

do miss ?

do miss something?

yes.

calling setrect() on qgraphicsrectitem not change pos(), changes position of rectangle draws, item's position unchanged. thus, r1 has pos of (0, 0), rectangle drawn @ (100, 100) offset pos().

to avoid confusion, it's easier leave rect @ (0, 0) , call setpos() on qgraphicsrectitem move want it.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -