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. QGraphcisView with QOpenGlWidget not updating properly on resize and scroll
Forum Updated to NodeBB v4.3 + New Features

QGraphcisView with QOpenGlWidget not updating properly on resize and scroll

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 4 Posters 1.0k 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.
  • H Offline
    H Offline
    Hristo Konstantinov
    wrote on 28 Aug 2021, 10:05 last edited by
    #1

    I have QScrollArea, which has a QWidget, which has a QGraphicsView with QOpenGLWidget set as a viewport. The GraphicsView contains QGraphicsItems which are also custom and draw QPixmaps in their paint function. The problem is that when I programmatically change the scroll position of the QScrollArea or resize the window, the GraphicItems which are left out of the visible viewport of QScrollArea don't update when they become visible again, unless I hover them with the mouse.

    Resize down:
    alt text
    Resize up back again:
    alt text
    After hovering with the mouse:
    alt text

    The problem arises only when I use QOpenGlWidget as a viewport, so I guess there is some miscommunication between the viewport of the QScrollArea and that of the GraphicsView. I've tried everything - from calling update() manually on QGraphicsView to setting all sorts of options like FullViewportUpdate, but nothing seems to work. The GraphicsView and its parent widget are heavy objects and I'm emulating a QTabWIdget, by using TabBar, which just sets the parameters of different "tab instances" (including the QScrollArea scroll bars position) onto a single view, creating the illusion of different opened widgets.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hristo Konstantinov
      wrote on 28 Aug 2021, 10:30 last edited by Hristo Konstantinov
      #2
      This post is deleted!
      1 Reply Last reply
      1
      • H Offline
        H Offline
        Hristo Konstantinov
        wrote on 28 Aug 2021, 11:19 last edited by
        #3

        A code snippet from my custom GraphicsView constructor:

        GraphicsView::GraphicsView(QWidget *parent)
        	: QGraphicsView(parent), gl{nullptr}{
        
        setRenderHints(QPainter::Antialiasing | 
                               QPainter::SmoothPixmapTransform);
        setCacheMode(QGraphicsView::CacheBackground);
        setDragMode(QGraphicsView::RubberBandDrag);
        setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
        	
        	gl = new QOpenGLWidget();
        	
        	QSurfaceFormat format;
        
        	format.setSamples(4);
        
        	gl->setFormat(format);
        	setViewport(gl);
        	gl->setUpdateBehavior(
                QOpenGLWidget::UpdateBehavior::NoPartialUpdate);
        	
        }
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Aug 2021, 18:29 last edited by
          #4

          Hi,

          Out of curiosity, why do you have your QGraphicsView inside a QScrollArea ?

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

          H 2 Replies Last reply 28 Aug 2021, 19:09
          0
          • S SGaist
            28 Aug 2021, 18:29

            Hi,

            Out of curiosity, why do you have your QGraphicsView inside a QScrollArea ?

            H Offline
            H Offline
            Hristo Konstantinov
            wrote on 28 Aug 2021, 19:09 last edited by Hristo Konstantinov
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • S SGaist
              28 Aug 2021, 18:29

              Hi,

              Out of curiosity, why do you have your QGraphicsView inside a QScrollArea ?

              H Offline
              H Offline
              Hristo Konstantinov
              wrote on 28 Aug 2021, 19:18 last edited by Hristo Konstantinov
              #6

              @SGaist My custom QWidget(which contains the graphic view) is inside of the QScrollArea, since it has dynamic changes in height, and usually is bigger then the monitor itself, so I need to scroll it's contents some how:

              alt text
              alt text

              If there is any better way, which lets me get around the problem, I am open to suggestions

              E 1 Reply Last reply 28 Aug 2021, 23:44
              0
              • H Offline
                H Offline
                Hristo Konstantinov
                wrote on 28 Aug 2021, 23:37 last edited by Hristo Konstantinov
                #7

                Okay guys, just tell me which function to call, to repaint the viewport of the QGraphicsView properly, by myself. I'll override every resize and every scroll event and call it there if I have to.

                1 Reply Last reply
                0
                • H Hristo Konstantinov
                  28 Aug 2021, 19:18

                  @SGaist My custom QWidget(which contains the graphic view) is inside of the QScrollArea, since it has dynamic changes in height, and usually is bigger then the monitor itself, so I need to scroll it's contents some how:

                  alt text
                  alt text

                  If there is any better way, which lets me get around the problem, I am open to suggestions

                  E Offline
                  E Offline
                  eyllanesc
                  wrote on 28 Aug 2021, 23:44 last edited by
                  #8

                  @Hristo-Konstantinov What @SGaist points out is that it is unnecessary to place a QGraphicsView in a QScrollArea since they both inherit from QAbstractScrollArea so if the content is very large then scrollbars will appear

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  H 1 Reply Last reply 29 Aug 2021, 13:00
                  1
                  • E eyllanesc
                    28 Aug 2021, 23:44

                    @Hristo-Konstantinov What @SGaist points out is that it is unnecessary to place a QGraphicsView in a QScrollArea since they both inherit from QAbstractScrollArea so if the content is very large then scrollbars will appear

                    H Offline
                    H Offline
                    Hristo Konstantinov
                    wrote on 29 Aug 2021, 13:00 last edited by
                    #9

                    @eyllanesc QGraphicsView has a fixed size. It is a child of the custom widget, which is very large. So I need QScrollArea not for the graphicsview, but for the widget, which holds the graphicsview

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 29 Aug 2021, 18:17 last edited by
                      #10

                      Hum... that sounds like a bug lurking...

                      You wrote that you have that issue when resizing programmatically, can you show how you do that ?

                      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
                      • H Offline
                        H Offline
                        Hristo Konstantinov
                        wrote on 30 Aug 2021, 00:35 last edited by Hristo Konstantinov
                        #11
                        ScrollPos TabView::getScrollPos()
                        {
                            return ScrollPos
                            {
                                ui.scrollArea->verticalScrollBar()->value(),
                                ui.scrollArea->horizontalScrollBar()->value()
                            };
                        }
                        
                        void TabView::setScrollPos(ScrollPos scrollPos)
                        {
                            ui.scrollArea->verticalScrollBar()->setValue(scrollPos.height);
                            ui.scrollArea->horizontalScrollBar()->setValue(scrollPos.width);
                        }
                        

                        I'm saving the scroll position in a vector of custom structs each time new tab is selected, and when I select the older tab, the presenter calls setScrollPos with the ScrollPos struct as an argument. Nothing fancy. But even if I resize the application window from the ui, if the graphicsview goes out of the viewport of the QScrollArea, the graphicitems in it that are hidden "outside" of the app window, don't draw themselves automatically when shown again, unless I hover them with the mouse. Now the question is how the mouse triggers their repainting and makes them appear again? If I know what does mouse hovering does on QGraphicsView to initialize the QOpenGl viewport repaint, I can call this function when I have to.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 30 Aug 2021, 20:17 last edited by
                          #12

                          Just to be sure I understand your architecture:

                          • you have a QTabBar
                          • on top of a QScrollArea
                          • inside of which you have a complex widget containing a QGraphicsView beside other widgets

                          Is that correct ?

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

                          H 1 Reply Last reply 30 Aug 2021, 21:37
                          0
                          • S SGaist
                            30 Aug 2021, 20:17

                            Just to be sure I understand your architecture:

                            • you have a QTabBar
                            • on top of a QScrollArea
                            • inside of which you have a complex widget containing a QGraphicsView beside other widgets

                            Is that correct ?

                            H Offline
                            H Offline
                            Hristo Konstantinov
                            wrote on 30 Aug 2021, 21:37 last edited by Hristo Konstantinov
                            #13

                            @SGaist Exactly. I don't want to use QTabWidget, because it creates a new Widget everytime a new tab is "opened", and my widget, which contains the graphicsview is heavy, so I just emulate that behavior. The view itself is always the same, placed inside the QScrollArea. The selected tab just sends signal to the presenter (I keep my business and QT logic separated via MVP), and that signal contains the index of the data (which is stored for each tab in a vector) and then the data is displayed on the widget, which is inside of the QScrollArea.

                            jsulmJ 1 Reply Last reply 31 Aug 2021, 09:36
                            0
                            • H Hristo Konstantinov
                              30 Aug 2021, 21:37

                              @SGaist Exactly. I don't want to use QTabWidget, because it creates a new Widget everytime a new tab is "opened", and my widget, which contains the graphicsview is heavy, so I just emulate that behavior. The view itself is always the same, placed inside the QScrollArea. The selected tab just sends signal to the presenter (I keep my business and QT logic separated via MVP), and that signal contains the index of the data (which is stored for each tab in a vector) and then the data is displayed on the widget, which is inside of the QScrollArea.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on 31 Aug 2021, 09:36 last edited by
                              #14

                              @Hristo-Konstantinov said in QGraphcisView with QOpenGlWidget not updating properly on resize and scroll:

                              I don't want to use QTabWidget, because it creates a new Widget everytime a new tab is "opened"

                              No, it does not create a widget every time a tab is selected, it shows the widget which was put on that tab.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              H 1 Reply Last reply 31 Aug 2021, 18:29
                              0
                              • jsulmJ jsulm
                                31 Aug 2021, 09:36

                                @Hristo-Konstantinov said in QGraphcisView with QOpenGlWidget not updating properly on resize and scroll:

                                I don't want to use QTabWidget, because it creates a new Widget everytime a new tab is "opened"

                                No, it does not create a widget every time a tab is selected, it shows the widget which was put on that tab.

                                H Offline
                                H Offline
                                Hristo Konstantinov
                                wrote on 31 Aug 2021, 18:29 last edited by Hristo Konstantinov
                                #15

                                @jsulm oh, you're right. So maybe the real reason was I had to take back ownership of the widget every time the tab was closed, so it wouldn't get destroyed. Have been writing this app ever since I started learning programming an year ago, and I can't remember all of my decisions, sorry.

                                1 Reply Last reply
                                0

                                1/15

                                28 Aug 2021, 10:05

                                • Login

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