Results 1 to 4 of 4

Thread: Live preview for graphics item in Qt

  1. #1
    Join Date
    Aug 2014
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Live preview for graphics item in Qt

    I am adding entities to QGraphicsScene by creating commands in QUndoFramework. An entity is pushed to the QUndoStack so that it is added to the scene.

    Qt Code:
    1. lineItem->setLine(start_p.x(), start_p.y(), move_p.x(), move_p.y());
    2. mUndoStack->push(new CadCommandAdd(this, lineItem));
    To copy to clipboard, switch view to plain text mode 

    where CadCommand is the command class to add entities and lineItem is the line added as an entity to the scene.

    The CadCommand has the undo and redo functions defined as:
    Qt Code:
    1. virtual void undo()
    2. {
    3. m_scene->removeItem(m_item); // m_scene is the QGraphicsScene, m_item is the QGraphicsItem
    4. }
    5.  
    6. virtual void redo()
    7. {
    8. m_scene->addItem(m_item);
    9. }
    To copy to clipboard, switch view to plain text mode 

    I am trying to achieve live preview of line until the mouse is clicked for second point to get its end point. The mousePressEvent is used to get the start and end points and mouseMoveEvent is used to get the updated coordinates of line's end point and an updated view is generated like:

    screenshot from 2014-11-07 15:40:21.png

    I want to add only the line joining First Click and Second Click to the scene. The other lines are such that the end point is the mouse position when mouse is moved in the scene. I want this to provide a live preview for the line and not that it should be added permanently in the drawing area.

    How to achieve a line having First Click and Second Click as end points only? And how to delete the previous lines which show the preview while the mouse is moved?

    Note: This is a cross question: http://stackoverflow.com/q/26799255/2828747

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Live preview for graphics item in Qt

    Quote Originally Posted by Kamalpreet View Post
    How to achieve a line having First Click and Second Click as end points only? And how to delete the previous lines which show the preview while the mouse is moved?
    I am afraid I don't understand the problem.

    It sounds like you are doing something like creating CadCommandAdd instances for every mouse move instead of just when you finish the line.
    If that is the case just don't do that.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2014
    Posts
    13
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Live preview for graphics item in Qt

    Quote Originally Posted by anda_skoa View Post
    It sounds like you are doing something like creating CadCommandAdd instances for every mouse move instead of just when you finish the line.
    If that is the case just don't do that.
    I have created an instance of CadCommandAdd only in mousePressEvent of the graphics scene when mouse is pressed for the first time when it is in graphics scene.
    While mouse is moved, only the updated position is obtained. No instances of CadCommandAdd are created while mouseMoveEvent.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Live preview for graphics item in Qt

    In that case my guess would be too aggressive caching.

    Cheers,
    _

Similar Threads

  1. ScrollArea for Graphics Item
    By karankumar1609 in forum Qt Programming
    Replies: 1
    Last Post: 11th July 2013, 13:38
  2. Graphics item highlight
    By mukunda in forum Qt Programming
    Replies: 1
    Last Post: 8th April 2011, 18:21
  3. Graphics Item
    By Maluko_Da_Tola in forum Newbie
    Replies: 4
    Last Post: 20th July 2010, 14:37
  4. Serialization and graphics item
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 12th November 2009, 11:03
  5. How do you embed a widget in a graphics item?
    By technoViking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 06:09

Tags for this Thread

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.