Painting issues with QT5
-
Hello,
While porting my app in Qt5, i have several problems with the call of the method paint in QGraphicsItem by example.
Example : i have a QGraphicsItem which works as a button.
I catch the signal pressed() , i change the button's color but the method paint is not called (i tried to force it by calling update() but it doesnt work too). So the new color never prints.
Then i catch the signal released() , I set the oldest color.So in my loop, the button's color never changes.
Any idea how to solve this problem? I hadn't this problem with Qt 4.6 but i setted the graphicssystem as raster and it isnt possible anymore in QT5.
Thanks.
-
Dunno about QGraphicsItem, but in SceneGraph you need to set itemHasContents property to true, otherwise the update will not be executed.
It looks like a porting bug, though, I think Qt devs would be interested to see it in the "bugtracker":https://qt-project.org/wiki/ReportingBugsInQt, together with a minimal example reproducing the issue.
-
Would be nice if you could give some more information
... e.g. what do you mean by "changing color", QGraphicsItem has no method for doing this ... so there must be some subclassing involved (e.g. QAbstractGraphicsShapeItem or a subclass of it like QGraphicsRectItem ... or some own implementation)btw. I think some behavior of QGraphics... changed around 4.6/4.7 ... so maybe it's not even a 4->5 issue, would be good if you could try your old code build and run with qt4.8 ...
-
In fact, i have a classe ButtonItem which inherits QGraphicsItem (so the method paint ...) but the event paint is never called between the event pressed and the event released. So there is no color changes.
My log :
ButtonItem::OnPress()
END ButtonItem::OnPress()
ButtonItem::OnReleased()
END ButtonItem::OnReleased()
ButtonItem::paint()
.... -
I think you have to add a call to "update()" in your onPress-handling and onRelease-handling ... maybe it was called automatically in older qt4 versions
... as I wrote in last post, there was some event-handling changed in 4.6 or 4.7 (I guess they reducing events for better performance in Quick1 ... but it broke my QGraphics-based Editor back then )... btw. while trying this I recognized that onRelease is only called if not calling onPress-function of baseclass (that's also a behavior, I wouldn't have expected ...)
-
In fact , it tried to call update() but it didnt work till i see we use a GraphicsProxyWidget in order to link with a QGraphicsItem . We called the function setCacheMode(QGraphicsItem::ItemCoordinateCache). So the method paint sometimes was never called.
But now i have problems in printing some other object by deleting the call of this function. lol