Results 1 to 6 of 6

Thread: Updating Foreground for QGraphicsView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Updating Foreground for QGraphicsView

    Hi all,

    I am writing a graph editor that allows user to add nodes and edges. The first node is added by left clicking on the viewport and subsequence clicks will added a node and an edge that links the new node to the previous node. I would like to draw a line interactively when the user moves the mouse around (not holding down any button) to help visualize the edge that will be created at different node position.

    I have subclassed the QGraphicsView and overridden the drawForeground and mouseMoveEvent. I have also set the mouse tracking to true. But the screen just doesn't seem to update itself properly. Below is the code for drawForeground and mouseMoveEvent. Hope someone can advice on this. Thanks.

    Qt Code:
    1. void MapView::mouseMoveEvent(QMouseEvent *event)
    2. {
    3. if(editing)
    4. {
    5. newPos = mapToScene(event->pos());
    6. update();
    7. }
    8.  
    9. void MapView::drawForeground(QPainter *painter, const QRectF &rect)
    10. {
    11. if(editing)
    12. {
    13. painter->setPen(Qt::white);
    14. painter->drawLine(oldPos, newPos);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 


    Thuan Seah Tan
    Last edited by wysota; 2nd January 2007 at 14:44. Reason: missing [code] tags

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.