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. Scale Scene wrong in second time.
QtWS25 Last Chance

Scale Scene wrong in second time.

Scheduled Pinned Locked Moved Solved General and Desktop
scenescaleqgraphicsview
7 Posts 2 Posters 3.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.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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 :)

      AlvaroSA 1 Reply Last reply
      0
      • mrjjM 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 :)

        AlvaroSA Offline
        AlvaroSA Offline
        AlvaroS
        wrote on last edited by
        #3

        @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..

        mrjjM 1 Reply Last reply
        1
        • AlvaroSA AlvaroS

          @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..

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

          @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.

          AlvaroSA 1 Reply Last reply
          0
          • mrjjM mrjj

            @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.

            AlvaroSA Offline
            AlvaroSA Offline
            AlvaroS
            wrote on last edited by
            #5

            @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!

            mrjjM 1 Reply Last reply
            1
            • AlvaroSA AlvaroS

              @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!

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

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

              AlvaroSA 1 Reply Last reply
              0
              • mrjjM mrjj

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

                AlvaroSA Offline
                AlvaroSA Offline
                AlvaroS
                wrote on last edited by
                #7

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

                Thanks a lot.

                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