Results 1 to 3 of 3

Thread: How to manage multi QGraphicsItem

  1. #1
    Join Date
    Oct 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Question How to manage multi QGraphicsItem

    Hello,
    I've a class Scene extending QGraphicsSceneand to catch click mouse i'm using the function mousePressEvent ( QGraphicsSceneMouseEvent* event ). This function is coded like:
    Qt Code:
    1. void Scene::mousePressEvent ( QGraphicsSceneMouseEvent* event ) {
    2. // set local variables and check if existing station clicked
    3. qreal x = event->scenePos().x();
    4. qreal y = event->scenePos().y();
    5.  
    6. GraphItem _item = dynamic_cast<GraphItem*> ( itemAt ( x, y ) );
    7.  
    8. if ( GraphItem == 0 && event->button() == Qt::LeftButton ) {
    9. m_undoStack->push ( new CommandGraphItemAdd ( this, x, y ) );
    10. emit message ( QString ( "GraphItem add at %1,%2" ).arg ( x ).arg ( y ) );
    11. }
    12.  
    13. QGraphicsScene::mousePressEvent ( event );
    14. this->update();
    15. }
    To copy to clipboard, switch view to plain text mode 

    My problem is how to create various QGraphicItem into the mousePressEvent function ? For example i click a button into menu option and a point is selecting, or a circle or other.
    My solution is using a switch that reads a value (for example an int value, it set when a button is clicked), but for me isn't optimal solution. What do you think?Exist any different solution?
    tnx so much
    Last edited by Marcofe; 16th October 2013 at 11:43.

  2. #2
    Join Date
    Mar 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanked 3 Times in 2 Posts

    Default Re: How to manage multi QGraphicsItem

    May be you could use factory pattern for creating the graphics items so that you could keep the changes minimal later.

  3. #3
    Join Date
    Oct 2013
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Android

    Default Re: How to manage multi QGraphicsItem

    JackHammer, I don't know this pattern and this is a way to learn a new thing about programming...so I’m looking for it.
    Tnx so much for your answer. I'll inform you for news. Bye

Similar Threads

  1. Replies: 8
    Last Post: 13th April 2012, 15:47
  2. multi-qgraphicsitem display help
    By mcarter in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2012, 23:10
  3. best way to manage forms?
    By skuda in forum Qt Programming
    Replies: 4
    Last Post: 7th December 2009, 08:38
  4. What is the best way to manage memory across threads?
    By bughunter2 in forum Qt Programming
    Replies: 2
    Last Post: 4th January 2009, 23:53
  5. How to manage QPainter?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:20

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.