Results 1 to 9 of 9

Thread: connecting lines?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default connecting lines?

    Hi, I can draw a line between two points and if the point moves the line moves too.
    But now I would like to draw a second line between the first point and another one. This works, but then the line isn't connected to the points.
    I don't know what's wrong, can somebody help me?
    Qt Code:
    1. void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *e)
    2. {
    3. pos=e->scenePos();
    4. end=e->scenePos();
    5. item = new EllipseItem(pos.x(), pos.y(),10,10);
    6. item2 = new EllipseItem(end.x(), end.y(),10,10);
    7. item->setFlags(QGraphicsItem::ItemIsMovable);
    8. item2->setFlags(QGraphicsItem::ItemIsMovable);
    9.  
    10. if(e->button() == Qt::LeftButton)
    11. {
    12. if(itemAt(pos))
    13. {QGraphicsScene::mousePressEvent(e); }
    14.  
    15. else
    16. {addItem(item);
    17. linie = new LineItem(item,item2);
    18. QObject::connect(item, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
    19. QObject::connect(item2, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
    20. addItem(linie);
    21. }
    22. }
    23.  
    24. if(e->button() == Qt::RightButton)
    25. {
    26. if(itemAt(pos))
    27. {
    28. linie = new LineItem(item,item2);
    29. QObject::connect(item, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
    30. QObject::connect(item2, SIGNAL(positionchanged()), linie , SLOT(updatePosition()));
    31. addItem(linie);
    32. }
    33. else
    34. { QGraphicsScene::mousePressEvent(e); }
    35. }
    36. }
    37.  
    38. void GraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *e)
    39. {
    40. if((e->buttons()==Qt::LeftButton) || (e->buttons()==Qt::RightButton))
    41. {item2->setPos(e->scenePos());
    42. item2->update();
    43. linie->updatePosition();
    44. linie->update();
    45. }
    46. QGraphicsScene::mouseMoveEvent(e);
    47. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by konvex; 14th December 2008 at 13:45.

Similar Threads

  1. Replies: 12
    Last Post: 18th September 2008, 15:04
  2. Connect to a server, send data and exit
    By Pepe in forum Newbie
    Replies: 6
    Last Post: 27th July 2007, 11:29
  3. How to draw lines with the right width?
    By albanelporto in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2006, 11:51
  4. Replies: 5
    Last Post: 28th August 2006, 14:36

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.