Saturday, 24 August 2013

undo or delete lines one by one on a QgraphicsScene

undo or delete lines one by one on a QgraphicsScene

I have a QGraphicsView subclass that load an image and user draw some line
on that image by click like this:
void TabView::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton) {
scene->addLine(line);
}
}
now i have to add undo. so I add a QList like this:
void TabView::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton) {
lineList<<line;
scene->addLine(lineList.last());
}
}
and for undo by Delete press
void TabView::keyPressEvent(QKeyEvent * event){
int key = event->key();
switch(key){
case Qt::Key_Delete:
{
lineList.removeLast();
foreach(QLineF line, lineList){
scene->addLine(line);
}
scene->update();
break;
}
}
}
nothing happen, I've tried this
case Qt::Key_Delete:
QGraphicsLineItem *item = new QGraphicsLineItem(lineList.last());
scene->removeItem(item);
scene->update();
break;
still nothing.
how I can undo or just delete items one by one on a QgraphicsScene? any
idea is well appreciated.

No comments:

Post a Comment