Unsolved Create a square in a scene with RubberBandDrag
-
Hello to everyone.
First of all thanks a lot for reading this post and being able to help.
I have an Scene where I would like to add a square item (polygon) just with RubberBandDrag mode.
So user clicks on scene and drag mouse and when users releases mouse then add the polygon.
How can I do that? thanks.
-
Hi
no sample for rubberband. sadlyMaybe this is interesting?
http://www.walletfox.com/course/qgraphicsitemruntimedrawing.php -
Hi.
I have an Scene where I would like to add a square item (polygon) just with RubberBandDrag mode.
So user clicks on scene and drag mouse and when users releases mouse then add the polygonsomething like this:
drawRect = QRectF(0, 0, 0, 0); connect(ui->graphicsView, &QGraphicsView::rubberBandChanged, [&](QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint){ if (rubberBandRect.isNull()) { ui->graphicsView->scene()->addRect(drawRect); drawRect = QRectF(0, 0, 0, 0); } else drawRect = QRectF(fromScenePoint, toScenePoint); });
-
@Devopia53 Thanks a lot my friend. It works.
Now, how can i disconnect it??
Because I would like to connect it when I press a button and when I press the same button again to disconnect it.Thanks again!
-
@Devopia53 said:
Hi.
I have an Scene where I would like to add a square item (polygon) just with RubberBandDrag mode.
So user clicks on scene and drag mouse and when users releases mouse then add the polygonsomething like this:
drawRect = QRectF(0, 0, 0, 0); connect(ui->graphicsView, &QGraphicsView::rubberBandChanged, [&](QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint){ if (rubberBandRect.isNull()) { ui->graphicsView->scene()->addRect(drawRect); drawRect = QRectF(0, 0, 0, 0); } else drawRect = QRectF(fromScenePoint, toScenePoint); });
@mrjj said:
Hi
no sample for rubberband. sadlyMaybe this is interesting?
http://www.walletfox.com/course/qgraphicsitemruntimedrawing.phpHello again. i have just figured it out the solution and it is the next:
if (check_generate_boxes_button == 0){ ui->graphicsView->blockSignals(false); connect(ui->graphicsView, &QGraphicsView::rubberBandChanged, [&](QRect rubberBandRect, QPointF fromScenePoint, QPointF toScenePoint){ if (rubberBandRect.isNull()) { rectangle = ui->graphicsView->scene()->addRect(drawRect); std::cout << "estoy en if" << std::endl; drawRect = QRectF(0, 0, 0, 0); rectangle->setFlag(QGraphicsRectItem::ItemIsSelectable, true); rectangle->setCursor(Qt::PointingHandCursor); } else{ drawRect = QRectF(fromScenePoint, toScenePoint); std::cout << "estoy en ELSE DEL if" << std::endl; } }); check_generate_boxes_button = 1; } else{ ui->graphicsView->blockSignals(true); check_generate_boxes_button = 0; }
I would like that the rectangle is selectable. It does not give me an error but when I select the rectangle that I define the program is unexpectedly finish.
Does anyone know why?
thanks!!!
-
A Stack Trace would help.
What are you doing with your rectangle variable ?
Is it deleted anywhere ?