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.
  • A Offline
    A Offline
    AlvaroS
    wrote on 13 Apr 2016, 07:50 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Apr 2016, 11:15 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 :)

      A 1 Reply Last reply 14 Apr 2016, 07:47
      0
      • M mrjj
        13 Apr 2016, 11:15

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

        A Offline
        A Offline
        AlvaroS
        wrote on 14 Apr 2016, 07:47 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..

        M 1 Reply Last reply 14 Apr 2016, 09:30
        1
        • A AlvaroS
          14 Apr 2016, 07:47

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

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 14 Apr 2016, 09:30 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.

          A 1 Reply Last reply 15 Apr 2016, 07:45
          0
          • M mrjj
            14 Apr 2016, 09:30

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

            A Offline
            A Offline
            AlvaroS
            wrote on 15 Apr 2016, 07:45 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!

            M 1 Reply Last reply 15 Apr 2016, 07:46
            1
            • A AlvaroS
              15 Apr 2016, 07:45

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 15 Apr 2016, 07:46 last edited by
              #6

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

              A 1 Reply Last reply 15 Apr 2016, 07:57
              0
              • M mrjj
                15 Apr 2016, 07:46

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

                A Offline
                A Offline
                AlvaroS
                wrote on 15 Apr 2016, 07:57 last edited by
                #7

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

                Thanks a lot.

                1 Reply Last reply
                0

                3/7

                14 Apr 2016, 07:47

                • Login

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