Results 1 to 18 of 18

Thread: Moving of QGraphicsItem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Moving of QGraphicsItem

    I'm using Qt 4.2.0 open source on windows. I did exactly what you did in the movie clip and it worked just like it should. Your exception confirms my belief that the item isn't removed properly. I can't tell you why, but you might simplify your code by removing the repeated calls to itemToIndex and indexToItem.
    Deleting objects in an event handler can be hairy. Try letting your items be subclasses of QObject as well and call QObject::deleteLater(). That might prevent the crash, but doesn't answer why the items aren't removed as they should.
    Good Luck!

  2. #2
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Moving of QGraphicsItem

    Can QGraphicsItems be subclassed by QObject?
    I tried that earlier, but then my program wouldn't compile.
    It didn't look like it fancyed QObject...

    I have seen the problem of deleting an item in an event handler, but I thought that was only for the items itself's event handlers. These items are deleted in the mainwindow's event handler.

    Thanks anyway,
    Erlend Graff

  3. #3
    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: Moving of QGraphicsItem

    Quote Originally Posted by Erlendhg View Post
    Can QGraphicsItems be subclassed by QObject?
    I tried that earlier, but then my program wouldn't compile.
    It didn't look like it fancyed QObject...
    Yes it can be done using multiple inheritance as follows. I guess someone had already asked this before. Probably you can find more info by forum search
    Anyway here is quick one

    Qt Code:
    1. class Item : public QObject, public QGraphicsItem
    2. {
    3. Q_OBJECT
    4. public:
    5. ..
    6.  
    7. public slots:
    8. ..
    9. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by Gopala Krishna; 15th May 2007 at 18:44. Reason: reformatted to look better
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  4. #4
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Unhappy Re: Moving of QGraphicsItem

    That doesn't seem to help either
    Even when I subclass QObject and use QObject::deleteLater() instead of deleting the item, I get the same bug.

  5. #5
    Join Date
    Nov 2006
    Posts
    29
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Talking Re: Moving of QGraphicsItem

    Ok, finally I found the solution of my quite annoying problem.
    It was me that hadn't read the documentation carefully enoughed, so I had missed that QGraphicsItem:repareGeometryChange() had to be called whenever I resize my timeline items :P

    After adding that, everything seems to work just fine
    Just wanted to tell, in case someone experiences similar problems:
    Remember to call QGraphicsItem:repareGeometryChange() before you change the boundingRect() of a QGraphicsItem

  6. The following user says thank you to Erlendhg for this useful post:

    Havard (27th June 2007)

Similar Threads

  1. Disable default tab behaviour for a QGraphicsItem
    By nmather in forum Qt Programming
    Replies: 3
    Last Post: 13th December 2017, 10:30
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. QGraphicsItem with QSizeGrip
    By elsheikhmh in forum Newbie
    Replies: 7
    Last Post: 19th November 2009, 18:53
  4. Deleting a scene from QGraphicsItem mouseEvent
    By JonathanForQT4 in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2007, 11:27
  5. why pushbutton moving??
    By Shuchi Agrawal in forum Qt Tools
    Replies: 7
    Last Post: 19th January 2007, 17:17

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
  •  
Qt is a trademark of The Qt Company.