thierry Joel
12th August 2016, 12:12
I know how to use the setDragMode in QGraphicsView to allow the user draw a rectangle on figure. I want an easy way to be able to do the same thing only this time around, when the user clicks and drags on the figure, a circle should be drawn, and not a rectangle. I dont know if that is possible, but i would really appreciate your suggestions.
Here is a section of my code:
void Scene::setMode(Mode mode){
sceneMode = mode;
QGraphicsView::DragMode vMode =
QGraphicsView::NoDrag;
if(mode == DrawCircle){
makeItemsControllable(false);
vMode = QGraphicsView::RubberBandDrag;
}
else if(mode == DrawRect){
makeItemsControllable(true);
vMode = QGraphicsView::RubberBandDrag;
}
QGraphicsView* mView = views().at(0);
if(mView)
mView->setDragMode(vMode);
}
void Scene::makeItemsControllable(bool areControllable){
foreach(QGraphicsItem* item, items()){
item->setFlag(QGraphicsItem::ItemIsSelectable,
areControllable);
item->setFlag(QGraphicsItem::ItemIsMovable,
areControllable);
}
}
When mode == DrawCircle, i want the user to be able to drag and draw a circle on the figure instead of a rectangle. Thanks in advance.
Here is a section of my code:
void Scene::setMode(Mode mode){
sceneMode = mode;
QGraphicsView::DragMode vMode =
QGraphicsView::NoDrag;
if(mode == DrawCircle){
makeItemsControllable(false);
vMode = QGraphicsView::RubberBandDrag;
}
else if(mode == DrawRect){
makeItemsControllable(true);
vMode = QGraphicsView::RubberBandDrag;
}
QGraphicsView* mView = views().at(0);
if(mView)
mView->setDragMode(vMode);
}
void Scene::makeItemsControllable(bool areControllable){
foreach(QGraphicsItem* item, items()){
item->setFlag(QGraphicsItem::ItemIsSelectable,
areControllable);
item->setFlag(QGraphicsItem::ItemIsMovable,
areControllable);
}
}
When mode == DrawCircle, i want the user to be able to drag and draw a circle on the figure instead of a rectangle. Thanks in advance.