Results 1 to 4 of 4

Thread: overlapping QGraphicsItem problem!!

  1. #1
    Join Date
    Jun 2006
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default overlapping QGraphicsItem problem!!

    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
    Attached Images Attached Images
    Last edited by boss_bhat; 27th January 2007 at 15:22. Reason: removed unwanted data

  2. #2
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping QGraphicsItem problem!!

    Quote Originally Posted by boss_bhat View Post
    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)
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: overlapping QGraphicsItem problem!!

    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

  4. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: overlapping QGraphicsItem problem!!

    Looks like there is again problem with boundingRect() as you did it here

    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.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  2. QGraphicsItem problem - how to save items info ??
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 17th October 2006, 12:17
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.