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. Update scene
QtWS25 Last Chance

Update scene

Scheduled Pinned Locked Moved Solved General and Desktop
updatesceneqgraphicsview
34 Posts 3 Posters 12.1k Views
  • 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #12

    Hi
    at returns const.
    This looks strange to me
    rectan.at(0) = Pos2;
    maybe
    rectan[0] = Pos2

    Also this will just swap the position in your list.
    It will NOT change on screen.

    You need to use pos() and SetPos
    Not just swap in you array. You swap pointers.
    You should swap QPointF using pos and setPos;

    mandruk1331M 1 Reply Last reply
    0
    • mrjjM mrjj

      Hi
      at returns const.
      This looks strange to me
      rectan.at(0) = Pos2;
      maybe
      rectan[0] = Pos2

      Also this will just swap the position in your list.
      It will NOT change on screen.

      You need to use pos() and SetPos
      Not just swap in you array. You swap pointers.
      You should swap QPointF using pos and setPos;

      mandruk1331M Offline
      mandruk1331M Offline
      mandruk1331
      wrote on last edited by
      #13

      @mrjj I thought it will repaint the rects, because first I delete them and then I want to repaint them with new options

      Mandruk1331

      mrjjM 1 Reply Last reply
      0
      • mandruk1331M mandruk1331

        @mrjj I thought it will repaint the rects, because first I delete them and then I want to repaint them with new options

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #14

        @mandruk1331

        Yes I guess it will repaint them on scene.
        But it matters not for scene if you swap your own array.
        The items still have same location as before as you do not setPos
        (from code shown)

        mandruk1331M 1 Reply Last reply
        0
        • mrjjM mrjj

          @mandruk1331

          Yes I guess it will repaint them on scene.
          But it matters not for scene if you swap your own array.
          The items still have same location as before as you do not setPos
          (from code shown)

          mandruk1331M Offline
          mandruk1331M Offline
          mandruk1331
          wrote on last edited by
          #15

          @mrjj and another one, I have a loop inside of a loop and when the second one finishes its iteration it won't singleshot on another iteration of the first loop

          for (int =0;i<10;i++){
          //and when i is 1 the second loop won't singleshot again
          for(int j=0;j<9;j++){
          SingleShot
          }
          }

          Mandruk1331

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #16

            well
            Normally it works as many times as u set it up but hard to guess at with
            only "SingleShot".

            mandruk1331M 1 Reply Last reply
            0
            • mrjjM mrjj

              well
              Normally it works as many times as u set it up but hard to guess at with
              only "SingleShot".

              mandruk1331M Offline
              mandruk1331M Offline
              mandruk1331
              wrote on last edited by
              #17

              @mrjj Why this code does not add the item, I don't understand, I remove it and then I want to re-add it with new options
              void MainWindow::Shot(){
              QGraphicsRectItem *t = new QGraphicsRectItem(rectan.at(0));

              scene->removeItem(rectan.at(1));

              rectan[1] = t;
              scene->addItem(rectan[1]);
              }

              Mandruk1331

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #18

                @mandruk1331 said:

                Why do yo u give rectan.at(0) to constructor ?
                new QGraphicsRectItem(rectan.at(0));

                Try
                scene->addItem( new QGraphicsRectItem );
                and tell if that not add a new item?

                mandruk1331M 1 Reply Last reply
                0
                • mrjjM mrjj

                  @mandruk1331 said:

                  Why do yo u give rectan.at(0) to constructor ?
                  new QGraphicsRectItem(rectan.at(0));

                  Try
                  scene->addItem( new QGraphicsRectItem );
                  and tell if that not add a new item?

                  mandruk1331M Offline
                  mandruk1331M Offline
                  mandruk1331
                  wrote on last edited by mandruk1331
                  #19

                  @mrjj Ok, I managed to swap positions of the rectangles, but they swap not always, at first execution they swap on the other they don't, what could be the problem??

                  void MainWindow::Shot(){
                  QPointF Pos1;
                  QPointF Pos2;
                  Pos1 = rectan.at(5)->pos();
                  Pos2 = rectan.at(6)->pos();

                  rectan.at(6)->setBrush(Qt::blue);
                  rectan.at(5)->setBrush(Qt::green);
                  // rectan.at(5)->setBrush(Qt::blue);
                  rectan.at(6)->setPos(Pos1.rx()-30,Pos1.ry());
                  rectan.at(5)->setPos(Pos2.rx()+30,Pos2.ry());

                  }
                  Solved it)

                  Mandruk1331

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #20

                    hi
                    put qDebug() << "in shot:"
                    in the
                    MainWindow::Shot()
                    to make sure its actually called mutiple times.

                    mandruk1331M 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      hi
                      put qDebug() << "in shot:"
                      in the
                      MainWindow::Shot()
                      to make sure its actually called mutiple times.

                      mandruk1331M Offline
                      mandruk1331M Offline
                      mandruk1331
                      wrote on last edited by
                      #21

                      @mrjj Pos2 = rectan.at(6)->scenePos(); - this one return (0,0), why? I tried pos() too

                      Mandruk1331

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #22

                        if pos() returns 0,0 , it must mean the items is actually at 0,0.

                        mandruk1331M 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          if pos() returns 0,0 , it must mean the items is actually at 0,0.

                          mandruk1331M Offline
                          mandruk1331M Offline
                          mandruk1331
                          wrote on last edited by
                          #23

                          @mrjj and the other ones return 0,0. The object are unique they are all parents and have no child, I want to get the positions of each object so I could move them

                          Mandruk1331

                          mrjjM 1 Reply Last reply
                          0
                          • mandruk1331M mandruk1331

                            @mrjj and the other ones return 0,0. The object are unique they are all parents and have no child, I want to get the positions of each object so I could move them

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #24

                            @mandruk1331
                            Something is not right.
                            Unless they are all really drawn at 0,0 then pos() should return the
                            actual position.
                            Did you new a QGraphicsRectItem and inserted directly in the list?

                            mandruk1331M 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              @mandruk1331
                              Something is not right.
                              Unless they are all really drawn at 0,0 then pos() should return the
                              actual position.
                              Did you new a QGraphicsRectItem and inserted directly in the list?

                              mandruk1331M Offline
                              mandruk1331M Offline
                              mandruk1331
                              wrote on last edited by
                              #25

                              @mrjj yes, and in the constructor I have set theirs poistions

                              Mandruk1331

                              mrjjM 1 Reply Last reply
                              0
                              • mandruk1331M mandruk1331

                                @mrjj yes, and in the constructor I have set theirs poistions

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #26

                                Ok, then they should still have the pos, unless you swapped with a
                                item having 0,0.

                                1 Reply Last reply
                                0
                                • mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #27

                                  Can I ask how any values (rects) you try to visualize?

                                  mandruk1331M 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    Can I ask how any values (rects) you try to visualize?

                                    mandruk1331M Offline
                                    mandruk1331M Offline
                                    mandruk1331
                                    wrote on last edited by
                                    #28

                                    @mrjj 10

                                    Mandruk1331

                                    mrjjM 1 Reply Last reply
                                    0
                                    • mandruk1331M mandruk1331

                                      @mrjj 10

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #29

                                      @mandruk1331
                                      ok.
                                      And did you write the sort also?

                                      mandruk1331M 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @mandruk1331
                                        ok.
                                        And did you write the sort also?

                                        mandruk1331M Offline
                                        mandruk1331M Offline
                                        mandruk1331
                                        wrote on last edited by
                                        #30

                                        @mrjj yes
                                        for( int i=0;i<random_numbers_.size()-1;i++){
                                        for(int j=0;j<random_numbers_.size()-1;j++){

                                               if(random_numbers_[j]>random_numbers_[j+1]){
                                                   count++;
                                        

                                        QTimer::singleShot(1000*count, [=]{ MainWindow::Shot(j);});

                                                }
                                            }
                                        }
                                        

                                        Mandruk1331

                                        1 Reply Last reply
                                        0
                                        • mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #31

                                          ok.
                                          Don't really look like bubble sort.
                                          :)

                                          mrjjM 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