Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Scale Scene wrong in second time.

    General and Desktop
    scene scale qgraphicsview
    2
    7
    2347
    Loading More Posts
    • 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.
    • AlvaroS
      AlvaroS last edited by

      Hi to all:

      First of all thanks a lot for helping me in this post.

      In my application,I create a QgraphicsScene adding lines when a user pushs a button. When the whole scene is created then the application scales the scene to the QGraphicsView. First time it works fine but when the user pushs the button again to add another lines, the scaling does not work fine... the QGraphicsView appears in blank... what I am doing wrong?

      This is the part of my code that i do this:

                      for (int i=0;i<num_lines;i++)
                      {
      
      ............................................
                          line = scene->addLine((lines_struct[i].x_start),(lines_struct[i].y_start),(lines_struct[i].x_end),(lines_struct[i].y_end), black);   //Cration of the scene
      ..........................................
                      }
           ui->graphicsView->scale(ui->graphicsView->width()/scene->width(),ui->graphicsView->height()/scene->height()); // Adjust map to the graphicsView using a scale
      

      It seems that the ui->graphicsView->scale does the scale in the original scene and not in the update scene...
      But I am not sure...
      Could anybody help me??

      Thanks a lot.

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by mrjj

        hi
        Second time u press "Add Lines" button, you say
        "the QGraphicsView appears in blank."

        How can that be ?
        the lines from first time should be there.

        Unless u maybe create a new scene ?
        You should only call scene = new QGraphicsScene()
        ONCE.

        Whatever is wrong, is NOT shown in that code listed here :)

        AlvaroS 1 Reply Last reply Reply Quote 0
        • AlvaroS
          AlvaroS @mrjj last edited by

          @mrjj Hello, thanks again for helping me.

          Yes, it appears in blank. The items are there but they do not appear because it does not scale fine.
          I have just one scene and I do "scene=new QGraphicsScene() " in the class constructor so just call once...

          I do not know what happens... When I add one line in the scene it scale fine, but when I do again the scale, scene appears in blank but I suppose that the items are there..

          mrjj 1 Reply Last reply Reply Quote 1
          • mrjj
            mrjj Lifetime Qt Champion @AlvaroS last edited by

            @AlvaroS
            Hi
            It sounds really odd.
            Maybe you can try the
            http://doc.qt.io/qt-5/qtwidgets-graphicsview-diagramscene-example.html
            (its available directly in Creator)

            With your AddLine code. It has zoom so easy to see if its just a zoom issues in your code or something else.

            AlvaroS 1 Reply Last reply Reply Quote 0
            • AlvaroS
              AlvaroS @mrjj last edited by

              @mrjj Hello again.
              It works fine if I write this line after scale:

               ui->graphicsView->fitInView(scene->itemsBoundingRect()); //Fit the view in the scene's bounding rect
              

              So now it works fine!

              mrjj 1 Reply Last reply Reply Quote 1
              • mrjj
                mrjj Lifetime Qt Champion @AlvaroS last edited by

                @AlvaroS
                Ok so it really was just a zoom problem ?

                AlvaroS 1 Reply Last reply Reply Quote 0
                • AlvaroS
                  AlvaroS @mrjj last edited by

                  @mrjj Yes it seems that...
                  So now it is solved ;)

                  Thanks a lot.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post