QGraphicsItem copy inside QGraphicScenes
-
Hi,
Do you mean some sort of drag and drop where the image contained in the "dropped" item is copied into the drop area which is your other item ?
-
Hi,
Do you mean some sort of drag and drop where the image contained in the "dropped" item is copied into the drop area which is your other item ?
-
Then you should take a look at the drag and drop robot example.
-
Then you should take a look at the drag and drop robot example.
@SGaist the example sho me the better usage of mouse event and mimedata.... but in my case not helph me.
In robot example robot is composed by multiple class item ..... headitem receive qimage... other only qcolour... in my case the item that receive qimage is generated from while do statement.... so I not know the item quontity at first time.So for do that i try to subclass qgraphicsscenes for manage mouse event in scene..... but this crash my app. In my subclass mouse event void there is nothing..... only empty void ... but these crash the app. If cancel mouse event reimplement void the crash disappear. Why?
An other strategy is using qlist<qgraphicsobject *> and graphicsscene chenge item signal for detect mouse pos in scene.... use ->contains macro for detect in whitch item is the mouse signal and than paint a new item in scene..... but is not elegant way to do the things.
Other better way?
Regards
Giorgio -
Weren't you trying to just copy the image from one graphics object inside another ? Or did I misunderstood ?
-
Weren't you trying to just copy the image from one graphics object inside another ? Or did I misunderstood ?
@SGaist said in QGraphicsItem copy inside QGraphicScenes:
Weren't you trying to just copy the image from one graphics object inside another
Yes is right, but robot example:
for (int i = 0; i < 10; ++i) { ColorItem *item = new ColorItem; item->setPos(::sin((i * 6.28) / 10.0) * 150, ::cos((i * 6.28) / 10.0) * 150); scene.addItem(item); } Robot *robot = new Robot; robot->setTransform(QTransform::fromScale(1.2, 1.2), true); robot->setPos(0, -20); scene.addItem(robot);
my case:
for (int i = 0; i < user_choose_these_number; ++i) { Robot *robot = new Robot; robot->setPos(calculationPos); scene.addItem(robot); } ColorItem *item = new ColorItem; ColorItem->addQImage /*static image, but resized from user gui*/ /*coloritem is moveable in my case see my code above... ColorItem = HighlightRectItem in my case*/ bla bla bla....
so is the inverse situation ..... robot can't select mimetype pos .... coloritem must select it ... and robot & coloritem isn't QObject (no signal slot).
Actually I create a new class to work with
HighlightRectItem::getPoint(QPointF myPointBox)
for emit a signal every time the user select new position of QImage show in HighlightRectItem..... I hope these work
regards
Giorgio -
The points are not related to drag and drop, they are just there to position stuff around the scene.
AFAIU, you should only have one type of item that you can drag and that you can drop on. I proposed the example as a way to learn how to create mime data and use it from a DnD point of view in your scene. Not as a replacement of what you are doing.
-
The points are not related to drag and drop, they are just there to position stuff around the scene.
AFAIU, you should only have one type of item that you can drag and that you can drop on. I proposed the example as a way to learn how to create mime data and use it from a DnD point of view in your scene. Not as a replacement of what you are doing.
@SGaist said in QGraphicsItem copy inside QGraphicScenes:
AFAIU ... what is means?? Sorry I'm not english ...
I proposed the example as a way to learn how to create mime data and use it
thanks a lot for these ... and I try use mime but is not possible because multiple element ... so now I try to make some type of signal send from my class .... that's all. I hope not to be rude .... unfortunately the English is not my preferred language.
regards
Giorgio -
In order to make a clean solutio I have subcalss my GraphicsScene and reimplement mouserelease event ... in these way I can grab mouse pos in scene at release .... I add
QVector<QRectF> for insert the box area in number choose from user .... after mouse release event in manwindow run these void:void MainWindow::testpos(QPointF testpoint) { if((ui->VBox_2->isOn) && !BoxVectV.empty()) { for ( int ibox = 0; ibox != BoxVectV.size(); ibox++) { if(BoxVectV[ibox].contains(testpoint.x(), testpoint.y())) { //QImage itmbximage = MainWindow::bxV.scaled(int(RealBoxSizeXX/4), int(RealBoxSizeYY/4) , Qt::IgnoreAspectRatio);*/ QPainter *itmbxpaint; itmbxpaint->drawImage(MainWindow::bxV_scal_pos.x(), MainWindow::bxV_scal_pos.y(), MainWindow::bxV_scal); QRectF tmpRect(BoxVectV[ibox].toRect()); QGraphicsRectItem *itmbx = new QGraphicsRectItem(); /* in these way crash app*/ itmbx->setRect(tmpRect); itmbx->setPos(tmpRect.topLeft()); itmbx->paint(itmbxpaint, 0, 0); scene_Pallet->addItem(itmbx); /*QGraphicsPixmapItem* item = new QGraphicsPixmapItem(); /* in these way not happen in grapicsscene .... is because z index?? item->setPixmap(QPixmap::fromImage(MainWindow::bxV_scal)); item->setPos(tmpRect.topLeft()); scene_Pallet->addItem(item);*/ //ibox = BoxVectV.size(); qDebug() << "this point image:...." << tmpRect.topLeft(); break; } } } if((ui->HBox_2->isOn) && !BoxVectH.empty()) { for ( int ibox = 0; ibox != BoxVectH.size(); ibox++) { if(BoxVectH[ibox].contains(testpoint.x(), testpoint.y())) { qDebug() << "this point:...." << testpoint; } } } }
debug show me the right info after every mouse release event ... but I'm not able to show my image (declare as static because I use it in other part of my app ...)
The image is ok ... if show it in other pos for example it show correct ...regards
giorgio -
In order to make a clean solutio I have subcalss my GraphicsScene and reimplement mouserelease event ... in these way I can grab mouse pos in scene at release .... I add
QVector<QRectF> for insert the box area in number choose from user .... after mouse release event in manwindow run these void:void MainWindow::testpos(QPointF testpoint) { if((ui->VBox_2->isOn) && !BoxVectV.empty()) { for ( int ibox = 0; ibox != BoxVectV.size(); ibox++) { if(BoxVectV[ibox].contains(testpoint.x(), testpoint.y())) { //QImage itmbximage = MainWindow::bxV.scaled(int(RealBoxSizeXX/4), int(RealBoxSizeYY/4) , Qt::IgnoreAspectRatio);*/ QPainter *itmbxpaint; itmbxpaint->drawImage(MainWindow::bxV_scal_pos.x(), MainWindow::bxV_scal_pos.y(), MainWindow::bxV_scal); QRectF tmpRect(BoxVectV[ibox].toRect()); QGraphicsRectItem *itmbx = new QGraphicsRectItem(); /* in these way crash app*/ itmbx->setRect(tmpRect); itmbx->setPos(tmpRect.topLeft()); itmbx->paint(itmbxpaint, 0, 0); scene_Pallet->addItem(itmbx); /*QGraphicsPixmapItem* item = new QGraphicsPixmapItem(); /* in these way not happen in grapicsscene .... is because z index?? item->setPixmap(QPixmap::fromImage(MainWindow::bxV_scal)); item->setPos(tmpRect.topLeft()); scene_Pallet->addItem(item);*/ //ibox = BoxVectV.size(); qDebug() << "this point image:...." << tmpRect.topLeft(); break; } } } if((ui->HBox_2->isOn) && !BoxVectH.empty()) { for ( int ibox = 0; ibox != BoxVectH.size(); ibox++) { if(BoxVectH[ibox].contains(testpoint.x(), testpoint.y())) { qDebug() << "this point:...." << testpoint; } } } }
debug show me the right info after every mouse release event ... but I'm not able to show my image (declare as static because I use it in other part of my app ...)
The image is ok ... if show it in other pos for example it show correct ...regards
giorgio@gfxx UPDATE : ... there are for shure z index problem .... now it work ... but not very fine.
/*why these way to show image crash the app??*/ QPainter *itmbxpaint; itmbxpaint->drawImage(MainWindow::bxV_scal_pos.x(), MainWindow::bxV_scal_pos.y(), MainWindow::bxV_scal); QRectF tmpRect(BoxVectV[ibox].toRect()); QGraphicsRectItem *itmbx = new QGraphicsRectItem(); itmbx->setRect(tmpRect); itmbx->setPos(tmpRect.topLeft()); itmbx->paint(itmbxpaint, 0, 0); scene_Pallet->addItem(itmbx); /* how to add z index??*/
regards
Giorgio