2

I am learning Qt and am trying to paint a simple display for my program with QPainter.

I draw static elements (frames etc.) once and only update dynamic elements afterwards.

Everything works fine, except for when the window loses focus. As soon as that happens, the whole area is cleared (dynamic elements keeps being painted as before).

Is it possible to prevent this behaviour? If not, how do I determine if the window have lost focus?

Arnold Spence
  • 21,942
  • 7
  • 74
  • 67
proarunas
  • 83
  • 10

2 Answers2

1

When your widget is uncovered, the paintEvent member will be called. The event passed in has a region() member that tells you what part of the widget should be redrawn. You can use that to redraw the static parts if/when necessary.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • Well I am using the regions, that's why only the active parts are redrawn. I wonder why the whole area is cleared on changing focus, and how to trigger the change for a full redraw if it is impossible to prevent the clear. – proarunas Jul 30 '11 at 13:49
0

While I did not find why the screen was repainted, the focus can be triggered by using

eventFilter(QObject *, QEvent *event) {
if (event->type() == QEvent::ActivationChange){}
}

and paint function can be called from here. Although a slight delay must be added, as the trigger usually fires before the window looses focus (hence still clearing the repaint).

proarunas
  • 83
  • 10