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 size updating
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView size updating

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 886 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.
  • H Offline
    H Offline
    HB76
    wrote on last edited by
    #1

    Hi everyone !

    I am facing a little problem with QGraphicsView and QStackedWidgets. I have created multiple views that are stored in a QStackedWidget. The problem is when I try to draw something in all these views and to make it fit the view rect, only the view that is above the stack is displayed correctly, the other views display at much smaller scales. Then, if I want the scale to adjust on a view, I need to show the view by moving it on top of the stack and refresh the scene.

    In fact, I checked the size property of all my QGraphicsView, and only the first (above) is correct, the other ones are very small like if the widget hasn't set it's size yet.

    I suspect the QStackWidget to be the problem... Do you have any idea of how to overcome this problem ? I've already tried all the classic methods like update(), setGeometry ... but it still doesn't works.

    Thanks !

    Pl45m4P 1 Reply Last reply
    0
    • H HB76

      Hi everyone !

      I am facing a little problem with QGraphicsView and QStackedWidgets. I have created multiple views that are stored in a QStackedWidget. The problem is when I try to draw something in all these views and to make it fit the view rect, only the view that is above the stack is displayed correctly, the other views display at much smaller scales. Then, if I want the scale to adjust on a view, I need to show the view by moving it on top of the stack and refresh the scene.

      In fact, I checked the size property of all my QGraphicsView, and only the first (above) is correct, the other ones are very small like if the widget hasn't set it's size yet.

      I suspect the QStackWidget to be the problem... Do you have any idea of how to overcome this problem ? I've already tried all the classic methods like update(), setGeometry ... but it still doesn't works.

      Thanks !

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @HB76

      I guess without seeing any code, nobody can help you :)

      How many scenes do you use? Did you set a sceneRect for each scene?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      H 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @HB76

        I guess without seeing any code, nobody can help you :)

        How many scenes do you use? Did you set a sceneRect for each scene?

        H Offline
        H Offline
        HB76
        wrote on last edited by HB76
        #3

        @Pl45m4 I use 5 QGraphicsViews with one QGraphicsScene for each one. All the views are distributed in differents workshops (that's why I didn't post code because I should have posted it at all). And sometimes in a same workshop it can have multiple View with a stack. All the workshops are also stored in a stack that is used as centralWidget in the mainWindow.

        I have also inherited the QGraphicsView class to have mouse click and mouve event but that's noot very relevant since the problem was already there before when I was using simple QGraphicsViews.

        Here is some code of one workshop :

            // Constructor
            viewerStack = new QStackedWidget(this);
            viewerStack->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
            scene1 = new QGraphicsScene(this);
            scene2 = new QGraphicsScene(this);
            view1 = new GraphicsView(scene1,viewerStack);
            view1->setDragMode(QGraphicsView::ScrollHandDrag);
            view2 = new GraphicsView(scene2,viewerStack);
            view2->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
            view2->setDragMode(QGraphicsView::ScrollHandDrag);
            viewerStack->addWidget(view1);
            viewerStack->addWidget(view2);
        
        
        void workshop::renderScene(int index)
        {
            scene1->clear();
            scene2->clear();
        
            if (!image_files->isEmpty() && index<image_files->count())
            {
                QImage image(image_files->value(index));
                scene1->addPixmap(QPixmap::fromImage(image));
                if (parameters.transform)
                view1->fitInView(scene1->sceneRect(),Qt::AspectRatioMode::KeepAspectRatio);
        
                QImage processedImage = ImageProcessingToolBox::processImage(image,parameters);
                scene2->setSceneRect(processedImage.rect());
                scene2->addPixmap(QPixmap::fromImage(processedImage));
                view2->fitInView(scene2->sceneRect(),Qt::AspectRatioMode::KeepAspectRatio);
            }
        }
        
        Pl45m4P 1 Reply Last reply
        0
        • H HB76

          @Pl45m4 I use 5 QGraphicsViews with one QGraphicsScene for each one. All the views are distributed in differents workshops (that's why I didn't post code because I should have posted it at all). And sometimes in a same workshop it can have multiple View with a stack. All the workshops are also stored in a stack that is used as centralWidget in the mainWindow.

          I have also inherited the QGraphicsView class to have mouse click and mouve event but that's noot very relevant since the problem was already there before when I was using simple QGraphicsViews.

          Here is some code of one workshop :

              // Constructor
              viewerStack = new QStackedWidget(this);
              viewerStack->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
              scene1 = new QGraphicsScene(this);
              scene2 = new QGraphicsScene(this);
              view1 = new GraphicsView(scene1,viewerStack);
              view1->setDragMode(QGraphicsView::ScrollHandDrag);
              view2 = new GraphicsView(scene2,viewerStack);
              view2->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
              view2->setDragMode(QGraphicsView::ScrollHandDrag);
              viewerStack->addWidget(view1);
              viewerStack->addWidget(view2);
          
          
          void workshop::renderScene(int index)
          {
              scene1->clear();
              scene2->clear();
          
              if (!image_files->isEmpty() && index<image_files->count())
              {
                  QImage image(image_files->value(index));
                  scene1->addPixmap(QPixmap::fromImage(image));
                  if (parameters.transform)
                  view1->fitInView(scene1->sceneRect(),Qt::AspectRatioMode::KeepAspectRatio);
          
                  QImage processedImage = ImageProcessingToolBox::processImage(image,parameters);
                  scene2->setSceneRect(processedImage.rect());
                  scene2->addPixmap(QPixmap::fromImage(processedImage));
                  view2->fitInView(scene2->sceneRect(),Qt::AspectRatioMode::KeepAspectRatio);
              }
          }
          
          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @HB76

          Does the same problem occur, if you use all views next to each other (without the StackedWidget)?


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          H 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @HB76

            Does the same problem occur, if you use all views next to each other (without the StackedWidget)?

            H Offline
            H Offline
            HB76
            wrote on last edited by HB76
            #5

            @Pl45m4 the problem does not appear if before drawing on each view, I show it (even empty) on screen. So yes if they are all next to each other and displayed on screen it works.

            That makes me think that there should be something with the initialisation of the QGraphicsView, like if the fact of storing it in stacks avoids them to initialise there geometry if they are not on top of the stack (probably because when they are on top it must create a showEvent and then adapt the size from the viewPort, which is actually the stack).

            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