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. Maximize QGraphicsView
Qt 6.11 is out! See what's new in the release blog

Maximize QGraphicsView

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 2 Posters 8.2k Views 1 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.
  • ivanicyI Offline
    ivanicyI Offline
    ivanicy
    wrote on last edited by
    #1

    Hello!

    I don't know if it could be possible, but maybe you could help me.

    I am showing an image in a QGraphicsView and I want to know if it is possible to maximize it when using double click, for example.

    Is it possible?

    Thank you very much!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      What exactly do you want to maximize (the GraphicsView or the Image), and what exactly do you mean by that? How should it look?

      ivanicyI 1 Reply Last reply
      0
      • A Asperamanca

        What exactly do you want to maximize (the GraphicsView or the Image), and what exactly do you mean by that? How should it look?

        ivanicyI Offline
        ivanicyI Offline
        ivanicy
        wrote on last edited by
        #3

        @Asperamanca

        This is that I want:

        When I doubleclick the image, I want to show it fullscreen and, doubleclicking again, I want to restore the default interface. Do you understand me? I know my english is not very good.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by
          #4

          If I understand you correctly, it's only zooming in onto the image, and then zooming out again.

          If you show the image within a QGraphicsItem (e.g. a QGraphicsPixmap item), you can use QGraphicsView::fitInView to show this image in full view. Before that, you can remember the position and zoom level by saving QGraphicsView::transform().
          If you

          ivanicyI 1 Reply Last reply
          0
          • A Asperamanca

            If I understand you correctly, it's only zooming in onto the image, and then zooming out again.

            If you show the image within a QGraphicsItem (e.g. a QGraphicsPixmap item), you can use QGraphicsView::fitInView to show this image in full view. Before that, you can remember the position and zoom level by saving QGraphicsView::transform().
            If you

            ivanicyI Offline
            ivanicyI Offline
            ivanicy
            wrote on last edited by
            #5

            @Asperamanca I am trying to get this effect:

            0_1508422247805_0fb74006-933c-4548-a998-12b5a6097ddc-imagen.png

            The image is a QGraphicPixmapItem in a QGraphicsScene in a QGraphicsView.

            I tryed this line in the mouseDoubleClickEvent():

            void imageView::mouseDoubleClickEvent(QMouseEvent *event) {
                fitInView(QApplication::desktop()->availableGeometry(-1), Qt::IgnoreAspectRatio);
            }
            

            but it doesn't works.

            Thank you very much

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              How big is your GraphicsView in the first picture? Does it already fill the whole rectangle (but the image is smaller), or does it only fill the gray area in the middle?
              Because if the GraphicsView does not fill the whole interface, you first need to maximize that. For this, you might get some info in this article: https://stackoverflow.com/questions/9412971/how-to-set-qwidget-fullscreen-but-real-fullscreen-change-resolution-set-mod#9413140

              ivanicyI 1 Reply Last reply
              0
              • A Asperamanca

                How big is your GraphicsView in the first picture? Does it already fill the whole rectangle (but the image is smaller), or does it only fill the gray area in the middle?
                Because if the GraphicsView does not fill the whole interface, you first need to maximize that. For this, you might get some info in this article: https://stackoverflow.com/questions/9412971/how-to-set-qwidget-fullscreen-but-real-fullscreen-change-resolution-set-mod#9413140

                ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by
                #7

                @Asperamanca The QGraphicsView and the image have the same size. In the QGraphicsView's showEvent, I put this line:

                fitInView(this->scene->sceneRect(), Qt::IgnoreAspectRatio);
                

                The 'this' pointer is the QGraphicsView. I have tryed this lines, but it doesn't work:

                void imageView::mouseDoubleClickEvent(QMouseEvent *event) {
                    this->setWindowState(Qt::WindowFullScreen);
                    this->showFullScreen();
                    fitInView(QApplication::desktop()->availableGeometry(-1), Qt::IgnoreAspectRatio);
                }
                

                imageView is the QGraphicsView.

                Do you know what could be the problem?? Thank you again!!

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  Asperamanca
                  wrote on last edited by
                  #8

                  First, this line in double click is unnecessary:

                  fitInView(QApplication::desktop()->availableGeometry(-1), Qt::IgnoreAspectRatio);
                  

                  because your image should already be fully zoomed in from the constructor.

                  Second, try to change the line in showEvent to the following

                  fitInView(myGraphicsPixmapItem, Qt::IgnoreAspectRatio);
                  

                  Finally, what do you mean by "it doesn't work": Is the whole window not maximized? Or is the image not large enough within the window?

                  ivanicyI 1 Reply Last reply
                  0
                  • A Asperamanca

                    First, this line in double click is unnecessary:

                    fitInView(QApplication::desktop()->availableGeometry(-1), Qt::IgnoreAspectRatio);
                    

                    because your image should already be fully zoomed in from the constructor.

                    Second, try to change the line in showEvent to the following

                    fitInView(myGraphicsPixmapItem, Qt::IgnoreAspectRatio);
                    

                    Finally, what do you mean by "it doesn't work": Is the whole window not maximized? Or is the image not large enough within the window?

                    ivanicyI Offline
                    ivanicyI Offline
                    ivanicy
                    wrote on last edited by
                    #9

                    @Asperamanca I mean that the image doesn't maximize. Now, when I doubleclick the image, the image gets small and then fill the QGraphicsView, but it doesn't fill in fullscreen, only the image square that I drew before.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Asperamanca
                      wrote on last edited by
                      #10

                      Okay, so your QGraphicsView is made fullscreen, but the image stays the same size.
                      This is because by default, when you resize a QGraphicsView, the content stays the same size.
                      You can find information on how to resize the content when you resize the GraphicsView in this article: https://stackoverflow.com/questions/24738458/qt-qgraphicsview-how-to-hook-to-resize-event#24738962

                      ivanicyI 1 Reply Last reply
                      0
                      • A Asperamanca

                        Okay, so your QGraphicsView is made fullscreen, but the image stays the same size.
                        This is because by default, when you resize a QGraphicsView, the content stays the same size.
                        You can find information on how to resize the content when you resize the GraphicsView in this article: https://stackoverflow.com/questions/24738458/qt-qgraphicsview-how-to-hook-to-resize-event#24738962

                        ivanicyI Offline
                        ivanicyI Offline
                        ivanicy
                        wrote on last edited by
                        #11

                        @Asperamanca No, sorry. The QGraphicsView has always the same size. It doesn't maximize. QgraphicsView and image have always the same size both.

                        0_1508498086138_fcac6278-5060-419c-a797-a9782117a6c3-imagen.png

                        The QGraphicsView never maximizes.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Asperamanca
                          wrote on last edited by
                          #12

                          @ivanicy said in Maximize QGraphicsView:

                          showFullScreen

                          Docs for showFullScreen state:
                          "Shows the widget in full-screen mode.
                          Calling this function only affects windows."

                          Check whether your QGraphicsView' isWindow() method returns true. If not, I believe you need to specify the flag Qt::Window in the constructor.
                          Or you make a QDialog or QMainWindow (which are a window by default), and insert the QGraphicsView as a full-size child window.

                          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