PDA

View Full Version : overlapping QGraphicsItem problem!!



boss_bhat
27th January 2007, 15:20
Hi all,

I am facing a problem when two QGraphicsItem movable items overlap on each other,
the overlapping surface of items is determined by the last QGraphicsView item added
to the QGraphicsScene. Say for example,
MainWindow:: MainWindow( QWidget *parent)
: QMainWindow(parent)
{
scene = new QGraphicsScene;
Shapes *Square= new Shapes; //where Shapes is subclass of QGraphicsItem
Shapes *Square1= new Shapes;

scene->addItem (square);
scene->addItem (square1);
triangle->setPos(0,0);
triangle1->setPos(100,60);

view = new QGraphicsView(scene); //make sure always pass the QGraphicsScene
view->setSceneRect(-400,-400,800,800);
setCentralWidget(view);
}
Please see the attached image, even when I try to move square1 on square2 in the overlapped area always the
square2 face will be exposed and square one will be hidden. Can somebody explain on how to solve this problem.
I mean to say the square which has the mouse press event should be the top surface when it is overlapping with another square.
Thanks in advance,
Prasanna Bhat

Gopala Krishna
27th January 2007, 15:45
I mean to say the square which has the mouse press event should be the top surface when it is overlapping with another square.


I am sorry as I couldn't understand your problem properly. Any way I feel you are looking for QGraphicsItem::setZvalue(). (Not sure though) :)

aamer4yu
27th January 2007, 17:30
yes he will have to use setZValue... the z values set initially remain so during the program.If you need that the item should come on top, set the zvalue to a highest value on mouse press so that it is drawn on top of others...
dont forget to set it back to original zvalue, if u are manipulating the items based on zvalue :)

Gopala Krishna
28th January 2007, 11:36
Looks like there is again problem with boundingRect() as you did it here (http://www.qtcentre.org/forum/f-qt-programming-2/t-drawing-problem-5293.html)

boundingRect() should return the bounding area of the item appropriately (For eg square of dim 0,0,100,100 should return not more or less than QRectF(0,0,100,100) ) otherwise it will cause all nuisances like above and also will significantly slow down your program.