Important: Please read the Qt Code of Conduct -

QPainter: Problem with drawing trajectory of a planet

  • Hi! I'm a novice in Qt development, so sorry for asking dumb questions.
    I found some example in Qt that uses QPainter and altered it for my case. I tried to draw a trajectory of a planet which revolves around a "Sun" and I succeeded. The thing I'm stuck in is I don't know how to tell the program to clear the background in the beginning and then not to continue clearing it because I want to see the trajectory of the planet.

    1. I tried setAutofillBackground(true), but it doesn't suit me cause it clears background all the time.
    2. Then I tried
      it does the same. If I turn clearing of background in both cases off , I get some messy imprint of my screen with different windows in it. Could you please give me an advice how to solve the problem?
      Thanks in advance!

  • You may try to set "Qt::WA_OpaquePaintEvent": attribute, but I suggest you paint the trajectory on a pixmap and then use the paint event to draw the pixmap on your widget.

  • Ok. I'll try that. Thanks!

Log in to reply