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. [solved] QGraphicsView in a QTabWidget
Forum Update on Monday, May 27th 2025

[solved] QGraphicsView in a QTabWidget

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.3k 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.
  • J Offline
    J Offline
    jtullos
    wrote on last edited by
    #1

    I've got multiple QGraphicsView items (in a custom class for a plot) on different tabs of a QTabWidget. When resizing, the QGraphicsView runs fitInView. However, this only works when the QGraphicsView is on the currently active tab. When a different tab is active, the view is not adjusted.

    I've noticed that the resize event only occurs when the tab containing the QGraphicsView is activated, but fitInView doesn't work if the resize occurs this way. It only works when I resize the window (such that the QGraphicsView is able to resize) with the QGraphicsView on the active tab.

    Any suggestions as to how I can make this behave?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      I don't exactly see what's the problem in receiving one resizeEvent instead of "many" (i.e. when the tab containing the QGraphicsView gets activated). Can you elaborate on that?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jtullos
        wrote on last edited by
        #3

        How to best explain this? I have 5 tabs. Tab 1 has a QGraphicsView object, Tab 3 has 2 QGraphicsView objects. I have each of these objects set to use fitInView whenever there is a resizeEvent received by the object.

        @
        void Plot2D::resizeEvent(QResizeEvent *event) {
        Q_UNUSED(event);
        myView->fitInView(myScene->sceneRect(),Qt::KeepAspectRatio);
        }
        @

        Here's an example of the behavior I'm seeing. I start the program on Tab 0. If I resize the window while Tab 0 is active, there are no resizeEvents triggered from any of the plots. If I switch to Tab 1, the plot on Tab 1 receives a resize event, but does not correct the view. If I resize while Tab 1 is active, the view is corrected. The same thing occurs for the plots on Tab 3.

        The desired behavior is for the view to be corrected whenever a resize event happens on the window. I am content with that occurring either immediately on the window resize or when the tab is activated. But it only happens when the tab containing the plot is already active.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jtullos
          wrote on last edited by
          #4

          Ok, I've found a solution. What I do is whenever the tab is changed, I force a resize event at that time to the plot.

          @
          QSize tempSize=tab1->plot->size();
          tab1->plot->resizeEvent(new QResizeEvent(tempSize,tempSize));
          @

          Not exactly how I was hoping to do it, but it solves the problem.

          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