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. QGraphicsView fitInView doesn't do anything on restore (down)
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView fitInView doesn't do anything on restore (down)

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 761 Views 2 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.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hello, I'm having a problem with QGraphicsView.
    I'm resizing an image on resize, but when I restore (down) the window, it keeps, and doesn't do anything:
    37a13fe2-cbac-4eb1-beb2-555c48e191de-image.png
    I have to resize it to go back to normal.
    Here's what I'm doing:

    ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      When are you doing that call ?
      Can you share your code ?

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

      S 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        When are you doing that call ?
        Can you share your code ?

        S Offline
        S Offline
        Sucharek
        wrote on last edited by
        #3

        Hi @SGaist, I'm calling QResizeEvent. Here's how:

        void MainWindow::resizeEvent(QResizeEvent*) {
              ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio);
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How do you do your restore ?

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sucharek
            wrote on last edited by
            #5

            I don't know how the button is named. It's this one: 82f83ff5-2d69-47d7-89af-eb0e2b01464d-image.png

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

              Silly question, did you check that resizeEvent is properly called when you click the restore button ?

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

              S 1 Reply Last reply
              0
              • SGaistS SGaist

                Silly question, did you check that resizeEvent is properly called when you click the restore button ?

                S Offline
                S Offline
                Sucharek
                wrote on last edited by
                #7

                Hi @SGaist, yes, everytime I resize, restore the window, it activates

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

                  Which version of Qt are you using ?
                  On which version of Windows ?
                  Can you provide a minimal compilable example that shows this behaviour ?

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

                  S 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Which version of Qt are you using ?
                    On which version of Windows ?
                    Can you provide a minimal compilable example that shows this behaviour ?

                    S Offline
                    S Offline
                    Sucharek
                    wrote on last edited by
                    #9

                    I'm using Qt 5.15.2
                    Windows 21H2
                    I don't know, only have an issue with resizing the picture, haven't found it in anything else

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

                      Just for the sake of testing, what happens if you trigger a single shot QTimer in the resizeEvent to trigger the fitInView ?

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

                      S 1 Reply Last reply
                      1
                      • SGaistS SGaist

                        Just for the sake of testing, what happens if you trigger a single shot QTimer in the resizeEvent to trigger the fitInView ?

                        S Offline
                        S Offline
                        Sucharek
                        wrote on last edited by
                        #11

                        Hi @SGaist, not sure what you meant by that, but I've got this:

                        QTimer timer;
                        timer.singleShot(1000, this, SLOT(QResizeEvent));
                        ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio);
                        

                        And it prints:

                        QObject::connect: Parentheses expected, slot MainWindow::QResizeEvent
                        QObject::connect:  (receiver name: 'MainWindow')
                        
                        JonBJ 1 Reply Last reply
                        0
                        • S Sucharek

                          Hi @SGaist, not sure what you meant by that, but I've got this:

                          QTimer timer;
                          timer.singleShot(1000, this, SLOT(QResizeEvent));
                          ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio);
                          

                          And it prints:

                          QObject::connect: Parentheses expected, slot MainWindow::QResizeEvent
                          QObject::connect:  (receiver name: 'MainWindow')
                          
                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @Sucharek
                          @SGaist meant more like:

                          QTimer timer;
                          timer.singleShot(1000, this, [this, svgLeft]() { ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio); });
                          
                          S 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @Sucharek
                            @SGaist meant more like:

                            QTimer timer;
                            timer.singleShot(1000, this, [this, svgLeft]() { ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio); });
                            
                            S Offline
                            S Offline
                            Sucharek
                            wrote on last edited by
                            #13

                            That actually works.
                            Thank you @SGaist and @JonB for helping me.

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Sucharek
                              wrote on last edited by
                              #14

                              Hi, just an improvement. Qt creator gave me errors, built anyway, but they were bothering me, so I've made a change:

                              timer.singleShot(0, this, [this]() {ui->graphicsView_LeftHand->fitInView(svgLeft, Qt::KeepAspectRatio);});
                              

                              Thanks again for helping me.

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

                                QTimer::singleShot is a static function so there's no need to create an instance for it.

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

                                1 Reply Last reply
                                3

                                • Login

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