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.
{
if(editing)
{
newPos = mapToScene(event->pos());
update();
}
{
if(editing)
{
painter->setPen(Qt::white);
painter->drawLine(oldPos, newPos);
}
}
void MapView::mouseMoveEvent(QMouseEvent *event)
{
if(editing)
{
newPos = mapToScene(event->pos());
update();
}
void MapView::drawForeground(QPainter *painter, const QRectF &rect)
{
if(editing)
{
painter->setPen(Qt::white);
painter->drawLine(oldPos, newPos);
}
}
To copy to clipboard, switch view to plain text mode
Thuan Seah Tan
Bookmarks