tts80
2nd January 2007, 04:23
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.
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);
}
}
Thuan Seah Tan
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.
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);
}
}
Thuan Seah Tan