QPOint pt_click;QGraphicsRectItem *rubber_rect_item;...rubber_rect_item = new QGraphicsRectItem();rubber_rect_item->setVisible(false);QPen rubber_pen;rubber_pen.setColor(QColor(Qt::red));rubber_pen.setWidth(2);rubber_pen.setCapStyle(Qt::RoundCap);rubber_pen.setStyle(Qt::DotLine);rubber_rect_item->setRect(0,0,1,1);rubber_rect_item->setVisible(false);rubber_rect_item->setPen(rubber_pen);
void CScene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ){pt_click = mouseEvent->scenePos();rubber_rect_item->setVisible(true);}
void CScene::mouseMoveEvent ( QGraphicsSceneMouseEvent * mouseEvent ){QRectF rectF;rectF.setBottomLeft(pt_click);rectF.setTopRight(mouseEvent->scenePos());QRectF norm_rect;norm_rect = rectF.normalized();rubber_rect_item->setRect(norm_rect);}