QML Scene not repainting
-
I am using QQmlIncubator and QQmlIncubationController to create QML components dynamically. Each component is currently just a Rectangle with a position, size and color. Each Rectangle is assigned the root QQuickItem as parentItem.
As long as the number of incubated items is low, everything works fine and displays correctly.
As soon as I incubate thousands of items (and have to call QQmlIncubationController::incubateFor multiple times inside a timer event), the scene simply stops to paint, i.e. none of the dynamically created items is visible.
It seems to be a repaint issue, because when I attach GammaRay to inspect the scene, suddenly everything paints correctly. But of course, this is not a solution that I can use daily...
I have tried the following things to force a repaint:
- Call QQuickItem::update on each item as it's incubation finishes
- Hide and Show the QQuickView once the incubation object count reaches zero
Do you have any other ideas what I might try?
-
I am using QQmlIncubator and QQmlIncubationController to create QML components dynamically. Each component is currently just a Rectangle with a position, size and color. Each Rectangle is assigned the root QQuickItem as parentItem.
As long as the number of incubated items is low, everything works fine and displays correctly.
As soon as I incubate thousands of items (and have to call QQmlIncubationController::incubateFor multiple times inside a timer event), the scene simply stops to paint, i.e. none of the dynamically created items is visible.
It seems to be a repaint issue, because when I attach GammaRay to inspect the scene, suddenly everything paints correctly. But of course, this is not a solution that I can use daily...
I have tried the following things to force a repaint:
- Call QQuickItem::update on each item as it's incubation finishes
- Hide and Show the QQuickView once the incubation object count reaches zero
Do you have any other ideas what I might try?
@Asperamanca
If anyone stumbles upon this in the future: Instead of using a slot to continue incubation, I simply used a lambda directly connected to the timer. I suspect that this lambda was not executed in the correct thread, and caused the issue. -
For dynamic objects look into Repeater and views with delegates. For non-item based objects look into Instantiator.
A lot of the views are more efficient if all of the Items you create are not visible at the same time. The advantage of these is they can all work from a model object from either QAbstractListModel (and other abstract models) or ListModel. I use Repeater to show items on a map.