Disappearing QQuickWidget Image -- Needs Constant Repainting
-
I am using the following source code in my
MainWindow::MainWindow()
function to load some QML on aQQuickWidget
: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?
-
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" } }
-
@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:
- When I do a
w.setSource(sURL)
, I also do aw.setProperty("chart",sURL)
to the same value. - I do
w.installEventFilter(this)
on the widget. - 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()
. - When I do a
-
@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.