Open xuniuer opened 2 years ago
I found a solution. in paint function, let widget to update manually, like this.
void VehicleObject::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
// Q_UNUSED(widget)
painter->setRenderHint(QPainter::Antialiasing,true);
painter->setPen(_fillColor);
painter->drawPixmap(_img->rect(), *_img);
// explicitly, call widget update method
widget->update();
}
Hi there,
I write a class VehicleObject, like CircleObject, inherited from MapGraphicsObject, to mark a vehicle position/state on map. The class will load a png file and paint in OSM tile map.
private member
_img
is declared as QPixmap*. Then I write a member function, like CircleObject classsetRadius(qreal radius)
In TestApp, I prepare a timer to change VehicleObject state, like this
In result, the png cannot be updated with timer's timeout event. However, the png file will change with mousewheel movement. Next, I use CircleObject to set with same logic except to change circle radius every 1 second, it works.
Any advice appreciated. Thanks.