Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to force Redraw
When I click a button on my QML scene, i need to hide a specific item, then call a C++ method to take a screenshot, and then show back my Item.
MyItem.visible = false;
MyItem.visible = true;
Unfortunately, the screenshot is taken before my Item is effectively hidden.
How can I force redraw or wait for the Item redraw before calling my C++ method ?
Use onVisibleChanged handler in MyItem. If not visible then TakeScreenShot()
Good idea, ... but it doesn't work.
I add a trace on the onVisibleChanged event. It is fired immediately after I modify the visible property and before the repaint job.
an other idea ? :-)
You mean that TakeScreenShot() gets called in onVisibleChanged before the item is invisible ?
[quote author="p3c0" date="1414645183"]You mean that TakeScreenShot() gets called in onVisibleChanged before the item is invisible ?[/quote]
Can you show us the code after changes ?
I just add this to MyItem :
At execution I have the log message 'onVisibleChanged:false' before a log message from my C++ method and the screenshot show MyItem.
Now that you have added it to MyItem you should call TakeScreenShot() there instead of onClicked handler as you did earlier
This ensures that the item is invisible before taking the screenshot.
It's difficult to take the ScreenShot here because i don't want a screenshot at each visible change.
I will test anyway to investigate.
But i disagree on your ;sentence : 'This ensures that the item is invisible before taking the screenshot." . This ensure that the visible property is set to false regardless the repaint is done or not.
I just made the test. The screenshot is taken when the Item is still visible.
It is clear that the event is fired when the property change. The repaint is done asynchronously.
I made a lot of search on internet and it seems there is no way to be notified of a repaint or to start a repaint manually.
What is the Item that you are making invisible ?
I tested it with a Rectangle. It works as expected. Can you post a complete sample code which shows the problem ?
It is a Rectangle.
I am using 5.4 Beta and i take the screenshot with the QQuickView::grabFrameBuffer() function.
You're right, i will make a complete sample code to test it.
thanks for your time :-)
According to the QQuickItem code "here":http://code.woboq.org/qt5/qtdeclarative/src/quick/items/qquickitem.cpp.html#_ZN17QQuickItemPrivate24setEffectiveVisibleRecurEb the signal visibleChanged() is emitted after the the item is made invisible; if I understood it correctly ;)