Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6214211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:50:13+00:00 2026-05-24T06:50:13+00:00

in my code I’m trying to draw points every time my app gets GPS

  • 0

in my code I’m trying to draw points every time my app gets GPS coordinates. The points are moved by "i" pixels to the right and down. I would like them to stay there drawn but it seems like the whole screen is always updated, even though I’m using a QRegion parameter which is meant to specify an area on the screen which should be updated. Is there anyone who could help, please? I’m really new at this and have no idea what is wrong.

Here is the class which handles this action:

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);
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:50:13+00:00Added an answer on May 24, 2026 at 6:50 am

    Your paintEvent must be able to repaint the entire widget. For example, if a user minimizes and then maximizes your application, the entire widget must be repainted. The QPaintEvent::region can be used to suppress some of that painting if those paint operations are expensive. Here is a sample. (This is only a proof of concept. There are a lot of “bad ideas” in the code below, not the least of which is that in this case the cost to test the region is not worth it. But it at least shows the logic.)

    #include <QtGui>
    
    class PaintWidget : public QWidget {
      Q_OBJECT
    public slots:
      void AddPoint() {
        QPoint point(rand() % width(), rand() % height());
        points_ << point;
        update(point.x() - 3, point.y() - 3, 6, 6);
      }
    protected:
      void paintEvent(QPaintEvent *event) {
        qDebug() << Q_FUNC_INFO;
        QPainter painter(this);
        painter.setPen(Qt::SolidLine);
        foreach (QPoint point, points_) {
          if (event->region().contains(point)) {
            qDebug() << "drawing point:" << point;
            painter.drawEllipse(point, 2, 2);
          }
        }
      }
    private:
      QVector<QPoint> points_;
    };
    
    int main(int argc, char** argv) {
      QApplication app(argc, argv);
    
      PaintWidget w;
      w.show();
    
      QTimer timer;
      timer.connect(&timer, SIGNAL(timeout()), &w, SLOT(AddPoint()));
      timer.start(1000);
    
      return app.exec();
    }
    
    #include "main.moc"
    

    Notice how if you leave the program visible, it paints individual dots with each paint event. But if you pass another window in front of yours, or minimize/maximize the application, many points are painted in one paint event.

    For drawing points, it is hard to see how considering the region could be of much benefit. But if your geographic points formed a QPainterPath or something like that, you may get some performance benefit.

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code Igniter version '2.0.3' Jquery 1.7 Jquery History plugin I have a CodeIgniter app
Code below works well on Firefox - displays progress bar which progresses on every
Code for webpage such that if anyone closes it, then next time when he
code id date time difference AiK4JJ kcy2000ok 2012-01-31 17:25:41 13 unBG1D gktoql 2012-01-31 17:25:35
code is here I am trying to make the Parent element visible when the
Code: //create the animation. $('img#header').hover(function(){ $(this).animate({top: -10px }, slow); I am trying to have
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {
Code: <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Unusual Array Lengths!</title> <script type=text/javascript> var arrayList = new Array();
Code I have: cell_val = CStr(Nz(fld.value, )) Dim iter As Long For iter =
Code and preview: <html> <head> <title>Testing some CSS</title> <style type=text/css> .dDay { font-size:205% }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.