Results 1 to 3 of 3

Thread: prepareGeometryChange problem

  1. #1
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default prepareGeometryChange problem

    I created two objects (node and line - derived from QGraphicsItem). Each line has pointers to its starting and ending node, and each node has pointer to QGraphicsItem in LinkedItems vector.
    Problem is when i move node i want to update line item, but i canot call prepareGeometryChange method because is protected. what's the reason of that? does anybody have an idea how to do this?
    Qt Code:
    1. void itdNode::move(qint32 _x, qint32 _y)
    2. {
    3. for (qint32 iItem=0;iItem<LinkedItems.size();iItem++)
    4. {
    5. // LinkedItems[iItem]->prepareGeometryChange();
    6. }
    7. prepareGeometryChange();
    8. x=_x;
    9. y=_y;
    10. update();
    11. for (qint32 iItem=0;iItem<LinkedItems.size();iItem++)
    12. {
    13. LinkedItems[iItem]->update();
    14. }
    15. }
    16. void itdNode::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
    17. {
    18. move(mouseEvent->scenePos().x(),mouseEvent->scenePos().y());
    19. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2008
    Posts
    27
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: prepareGeometryChange problem

    Do you realy need to call prepareGeometryChange()? Why? If I am not wrong ,you only need to call that when the boundingRect changes ,does the boundingRect of a line change when you move a node?
    Anyway,if you need to call that ,declare itdNode as a friend in line class ( friend class Line ; or whatever the name of the class is) .
    If God has friends ,then I cant be God.

  3. #3
    Join Date
    May 2008
    Location
    Rijeka, Croatia
    Posts
    85
    Thanks
    10
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: prepareGeometryChange problem

    LinkedItems is vector of pointers to QGraphicsItem, so i should in QGraphicsItem class declare friend node class. The best way is to create myItem class which inhertis QGraphicsItem, and has friends (Node, Line, etc.). Then node and line classes inherits myItem. I think that that would do the trick.
    Qt Code:
    1. class itdItem : public QGraphicsItem
    2. {
    3. friend class itdLine;
    4. friend class itdNode;
    5. }
    6. class itdLine : public itdItem
    7. class itdNode: public itdItem
    To copy to clipboard, switch view to plain text mode 
    now i can create in each (new or existing) object a list of pointers to linked items. cool

    thank you for your friendly friend suggestion

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 10:35
  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.