Results 1 to 4 of 4

Thread: QGraphicScene and different topmost QGraphicItem

  1. #1
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    3

    Angry QGraphicScene and different topmost QGraphicItem

    Hi,

    I've a slot as follows:

    Qt Code:
    1. qDeleteAll( scene.items() );
    2.  
    3. QGraphicsEllipseItem *el = new QGraphicsEllipseItem(-100,-300,200,200);
    4. el->setBrush( QBrush(Qt::green) );
    5. scene.addItem( el );
    6. QGraphicsEllipseItem *el1 = new QGraphicsEllipseItem(-300,-100,200,200);
    7. el1->setBrush( QBrush(Qt::green) );
    8. scene.addItem( el1 );
    9. QGraphicsEllipseItem *el2 = new QGraphicsEllipseItem(-100,100,200,200);
    10. el2->setBrush( QBrush(Qt::green) );
    11. scene.addItem( el2 );
    12. QGraphicsEllipseItem *el3 = new QGraphicsEllipseItem(100,-100,200,200);
    13. el3->setBrush( QBrush(Qt::green) );
    14. scene.addItem( el3 );
    15.  
    16. scene.addLine( 0,-400, 0, 400 );
    17. scene.addLine( -400,0, 400, 0 );
    18.  
    19. setScene(&scene);
    20.  
    21. fitInView(scene.itemsBoundingRect());
    To copy to clipboard, switch view to plain text mode 

    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.



    Does anybody know what I'm doing wrong?
    Last edited by jpn; 5th December 2007 at 07:43. Reason: changed [quote] to [code] tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicScene and different topmost QGraphicItem

    You may use QGraphicsItem::setZValue() to adjust the stacking order of graphics items.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    Xaar (5th December 2007)

  4. #3
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    3

    Default Re: QGraphicScene and different topmost QGraphicItem

    Quote Originally Posted by jpn View Post
    You may use QGraphicsItem::setZValue() to adjust the stacking order of graphics items.
    This is what I was looking for
    Thaks a lot.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicScene and different topmost QGraphicItem

    You might also want to turn on antialiasing for the view Those ellipses don't look very good.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.