PDA

View Full Version : QGraphicScene and different topmost QGraphicItem



Xaar
5th December 2007, 00:36
Hi,

I've a slot as follows:



qDeleteAll( scene.items() );

QGraphicsEllipseItem *el = new QGraphicsEllipseItem(-100,-300,200,200);
el->setBrush( QBrush(Qt::green) );
scene.addItem( el );
QGraphicsEllipseItem *el1 = new QGraphicsEllipseItem(-300,-100,200,200);
el1->setBrush( QBrush(Qt::green) );
scene.addItem( el1 );
QGraphicsEllipseItem *el2 = new QGraphicsEllipseItem(-100,100,200,200);
el2->setBrush( QBrush(Qt::green) );
scene.addItem( el2 );
QGraphicsEllipseItem *el3 = new QGraphicsEllipseItem(100,-100,200,200);
el3->setBrush( QBrush(Qt::green) );
scene.addItem( el3 );

scene.addLine( 0,-400, 0, 400 );
scene.addLine( -400,0, 400, 0 );

setScene(&scene);

fitInView(scene.itemsBoundingRect());


When I call this slot I have different QGraphicItem at top. Sometimes is a line and sometimes a ellipse ?(
What should I do to have always lines the topmost items?

I hope I clearly explain what is my problem. To be sure here is a PrintScreen, you can see that left ellipse is over the line, but others are below. This is a first call for this slot.

http://fraktal.wmp.uksw.edu.pl/~kamil/a.JPG

Does anybody know what I'm doing wrong?

jpn
5th December 2007, 07:54
You may use QGraphicsItem::setZValue() to adjust the stacking order of graphics items.

Xaar
5th December 2007, 17:45
You may use QGraphicsItem::setZValue() to adjust the stacking order of graphics items.

This is what I was looking for :D
Thaks a lot.

wysota
5th December 2007, 17:58
You might also want to turn on antialiasing for the view ;) Those ellipses don't look very good.