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. Disappearing QQuickWidget Image -- Needs Constant Repainting
QtWS25 Last Chance

Disappearing QQuickWidget Image -- Needs Constant Repainting

Scheduled Pinned Locked Moved General and Desktop
qquickwidgetqmlrepaintqchart.jsqchart
8 Posts 2 Posters 2.8k 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.
  • M Offline
    M Offline
    maximo
    wrote on last edited by maximo
    #1

    I am using the following source code in my MainWindow::MainWindow() function to load some QML on a QQuickWidget:

    ui->myQuickWidget->setSource("my.qml");
    

    The trouble I'm having is that this widget is on a tab, and when I click to view the other tab and then click back, the data is gone. The solution I came up with was to throw this in MainWindow::paintEvent(). However, that seems messy because it will keep repainting that constantly with every mouse move.

    How do I keep from having to repaint this widget all the time?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @maximo said:
      Hi, what is inside
      my.qml ?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maximo
        wrote on last edited by
        #3
        import QtQuick 2.0
        
        import "."
        import "QChart.js"        as Charts
        import "QChartGallery.js" as ChartsData
        
        Chart {
          id: chart_bar;
          width: 300;
          height: 300;
          chartAnimated: false;
          chartData: ChartsData.ChartBarData;
          chartType: Charts.ChartType.BAR;
        }
        
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          hi
          tried to put it in "Qt Quick Widgets Example"
          but it just crashes - so cant say if I can reproduce it.

          However, could you try the sample and see if its only drawn once?
          In the sample it keeps spinning.

          import QtQuick 2.0
          
          Rectangle {
              id: root
          
              Rectangle {
                  property int d: 100
                  id: square
                  width: d
                  height: d
                  anchors.centerIn: parent
                  color: "red"
                  NumberAnimation on rotation { from: 0; to: 360; duration: 2000; loops: Animation.Infinite; }
              }
              Text {
                  anchors.centerIn: parent
                  text: "Qt Quick running in a widget"
              }
          }
          
          M 1 Reply Last reply
          1
          • mrjjM mrjj

            hi
            tried to put it in "Qt Quick Widgets Example"
            but it just crashes - so cant say if I can reproduce it.

            However, could you try the sample and see if its only drawn once?
            In the sample it keeps spinning.

            import QtQuick 2.0
            
            Rectangle {
                id: root
            
                Rectangle {
                    property int d: 100
                    id: square
                    width: d
                    height: d
                    anchors.centerIn: parent
                    color: "red"
                    NumberAnimation on rotation { from: 0; to: 360; duration: 2000; loops: Animation.Infinite; }
                }
                Text {
                    anchors.centerIn: parent
                    text: "Qt Quick running in a widget"
                }
            }
            
            M Offline
            M Offline
            maximo
            wrote on last edited by
            #5

            @mrjj I tried your example. Indeed, it stayed on the widget and kept spinning, even when I changed tabs. So, it appears the issue is in how this third-party library I'm using works. I'm using Julien Wintz's QChart.js API.

            Here's how I did a workaround for now:

            1. When I do a w.setSource(sURL), I also do a w.setProperty("chart",sURL) to the same value.
            2. I do w.installEventFilter(this) on the widget.
            3. I then have a function like so:
            bool MainWindow::eventFilter(QObject *obj, QEvent *event)
            {
                QString sChart = obj->property("chart").toString();
                if (sChart.length() > 0) {
                    if (event->type() == QPaintEvent::Paint) {
                        QString s = obj->property("chart").toString();
                        QQuickWidget *w = this->findChild<QQuickWidget *>(obj->objectName());
                        w->setSource(sChart);
                    }
                }
            }
            

            I assume that this is a little lighter on the CPU than intercepting the entire MainWindow's paintEvent().

            mrjjM 1 Reply Last reply
            0
            • M maximo

              @mrjj I tried your example. Indeed, it stayed on the widget and kept spinning, even when I changed tabs. So, it appears the issue is in how this third-party library I'm using works. I'm using Julien Wintz's QChart.js API.

              Here's how I did a workaround for now:

              1. When I do a w.setSource(sURL), I also do a w.setProperty("chart",sURL) to the same value.
              2. I do w.installEventFilter(this) on the widget.
              3. I then have a function like so:
              bool MainWindow::eventFilter(QObject *obj, QEvent *event)
              {
                  QString sChart = obj->property("chart").toString();
                  if (sChart.length() > 0) {
                      if (event->type() == QPaintEvent::Paint) {
                          QString s = obj->property("chart").toString();
                          QQuickWidget *w = this->findChild<QQuickWidget *>(obj->objectName());
                          w->setSource(sChart);
                      }
                  }
              }
              

              I assume that this is a little lighter on the CPU than intercepting the entire MainWindow's paintEvent().

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              @maximo
              Hi. ok. so for some reason the chart only paint once.
              You could ask in Quick forum if they have an idea as they are very into Quick. Im pretty sure
              its easy to fix in the QML.

              But nice workaround :)

              Might also have used
              QTabWidget::currentChanged(int index) (its a signal)
              And then setSource(sChart); when switching to that tab.

              M 1 Reply Last reply
              0
              • mrjjM mrjj

                @maximo
                Hi. ok. so for some reason the chart only paint once.
                You could ask in Quick forum if they have an idea as they are very into Quick. Im pretty sure
                its easy to fix in the QML.

                But nice workaround :)

                Might also have used
                QTabWidget::currentChanged(int index) (its a signal)
                And then setSource(sChart); when switching to that tab.

                M Offline
                M Offline
                maximo
                wrote on last edited by
                #7

                @mrjj I liked your workaround better, so I implemented that instead. It was even less CPU intensive than the last workaround I was using.

                mrjjM 1 Reply Last reply
                0
                • M maximo

                  @mrjj I liked your workaround better, so I implemented that instead. It was even less CPU intensive than the last workaround I was using.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @maximo
                  Ok :)
                  I think to get it to repaint itself is easy for Quick experts
                  but if this works for you, then its ok, i guess.

                  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