[Qt-interest] Problem with QPainter in paintEvent

BaH woollybah at gmail.com
Wed Jul 29 10:05:50 CEST 2009


Thanks for everyone's assistance on this.

Examining the source for QPainter, it seems begin(device) and
QPainter(device) work slightly differently, and if I do as suggested below,
it works as expected.
I also think it makes a difference using the stack rather than the heap, for
whatever reason, as I was never able to get "new QPainter()" to work without
the error messages.

I've had to rearrange things somewhat in order to pass the QPainter pointer
into the framework :

void MaxQWidget::paintEvent(QPaintEvent * event) {
    QPainter p(this);
    _qt_qwidget_QWidget__OnPaintEvent(maxHandle, event,
_qt_qpainter_QPainter__create(&p));
}

but everything looks to be working now, and the analog clock example is
ticking and resizing nicely.
It also happens to make the implementation a little tidier, since the user
won't now be required to begin()/end() in the paintEvent().

Language binding can be quite depressing sometimes when seemingly simple
things don't work as you'd expect them to. But things are moving forward
now!

Thanks again for your help.

:o)

Brucey


2009/7/29 Ender EREL <erelender at yahoo.com>

> Are you deleting the painter you have created? If in every event you
> create a qpainter, you call begin but when you are finished, you do not
> delete the painter, therefore for the rest of the execution the painter
> lives.
>
> You may want to try it like this:
> void _qt_qwidget_QWidget__OnPaintEvent(maxHandle,event)
> {
>        QPainter painter(this); //calls begin automatically;
>        // your painting tasks
> }
> This way when the end of the function scope is reached, painter gets
> destroyed.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090729/a46a2685/attachment.html 


More information about the Qt-interest-old mailing list