私のコードでは、アプリが GPS 座標を取得するたびにポイントを描画しようとしています。ポイントは、「i」ピクセルだけ右および下に移動します。描画したままにしたいのですが、更新する必要がある画面上の領域を指定するための QRegion パラメータを使用しているにもかかわらず、画面全体が常に更新されているようです。助けてくれる人はいますか?私はこれが本当に初めてで、何が悪いのかわかりません。
このアクションを処理するクラスは次のとおりです。
GameField::GameField(QWidget *parent)
: QWidget(parent)
{
i=5;
j=0;
pen=new QPen(Qt::black, 1, Qt::SolidLine);
painter= new QPainter(this);
}
void GameField::paintEvent(QPaintEvent *event)
{
painter.setPen(pen);
painter.drawPoint(i,i,1,1);
}
void GameField::positionUpdated(QGeoPositionInfo position) {
QGeoCoordinate coordinates;
if (position.isValid()) {
coordinates = position.coordinate();
}
i=i+5;
QRegion region(QRect(i,i,5,5));
this->update(region);
}