Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsItem copy inside QGraphicScenes

QGraphicsItem copy inside QGraphicScenes

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    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 ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    gfxxG 1 Reply Last reply
    0
    • SGaistS SGaist

      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 ?

      gfxxG Offline
      gfxxG Offline
      gfxx
      wrote on last edited by
      #3

      @SGaist said in QGraphicsItem copy inside QGraphicScenes ....:

      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 ?

      yes exactly these.......

      Giorgio

      bkt

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Then you should take a look at the drag and drop robot example.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        gfxxG 1 Reply Last reply
        0
        • SGaistS SGaist

          Then you should take a look at the drag and drop robot example.

          gfxxG Offline
          gfxxG Offline
          gfxx
          wrote on last edited by
          #5

          @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

          bkt

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Weren't you trying to just copy the image from one graphics object inside another ? Or did I misunderstood ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            gfxxG 1 Reply Last reply
            0
            • SGaistS SGaist

              Weren't you trying to just copy the image from one graphics object inside another ? Or did I misunderstood ?

              gfxxG Offline
              gfxxG Offline
              gfxx
              wrote on last edited by gfxx
              #7

              @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

              bkt

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                gfxxG 1 Reply Last reply
                0
                • SGaistS SGaist

                  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.

                  gfxxG Offline
                  gfxxG Offline
                  gfxx
                  wrote on last edited by
                  #9

                  @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

                  bkt

                  1 Reply Last reply
                  0
                  • gfxxG Offline
                    gfxxG Offline
                    gfxx
                    wrote on last edited by
                    #10

                    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

                    bkt

                    gfxxG 1 Reply Last reply
                    0
                    • gfxxG gfxx

                      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

                      gfxxG Offline
                      gfxxG Offline
                      gfxx
                      wrote on last edited by
                      #11

                      @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

                      bkt

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved