[Qt-interest] Problem with QPainter in paintEvent

Samuel Rødal sroedal at trolltech.com
Wed Jul 29 08:24:25 CEST 2009


BaH wrote:
> Hi list,
> 
> I'm in the process of writing a Qt language binding for BlitzMax, which 
> appeared to be going very well. Current testing is on OS X, latest Qt 
> source release, cocoa build. But I appear to have hit a wall when it 
> comes to using a QPainter inside a paintEvent of a subclassed QWidget.
> 
> Everything in the code looks fine, but I get this output on the console :
> 
> QPainter::begin: A paint device can only be painted by one painter at a 
> time.
> 
> 
> So, I assume I've done something wrong somewhere...
> 
> Here's some of the relevant code :
> 
> 
> class MaxQWidget : public QWidget
> 
> {
> 
> Q_OBJECT
> 
> 
> public:
> 
> MaxQWidget(BBObject * handle, QWidget * parent, Qt::WindowFlags flags);
> 
> ~MaxQWidget();
> 
> 
> protected:
> 
> void paintEvent(QPaintEvent * event);
> 
> private:
> 
> BBObject * maxHandle;
> 
> };
> 
> 
> 
> and paintEvent() is implemented as this :
> 
> 
> void MaxQWidget::paintEvent(QPaintEvent * event) {
> 
> _qt_qwidget_QWidget__OnPaintEvent(maxHandle, event);
> 
> }
> 
> 
> 
> which simply passes the event up into the BlitzMax framework, causing 
> the BlitzMax paintEvent() method to be called.
> In this method, I create a new instance of a QPainter, of which the glue 
> looks like this :
> 
> 
> QPainter * bmx_qt_qpainter_create() {
> 
> return new QPainter();
> 
> }
> 
> 
> 
> I then call painter->begin() passing in the QWidget pointer.
> At this point, the error is output on the console.
> begin() returns 0, which is expected, due to the error.
> 
> I can't see anything obvious that I may have missed.
> 
> paintEvent() is called every tick of a QTimer, and anytime I resize the 
> window, so there's nothing wrong there. But for some reason, the QWidget 
> appears to already be painting when my paintEvent() is called.
> 
> Have I completely overlooked something?
> I've basically implemented a direct port of the analogclock example in 
> BlitzMax, which is pretty much line-for-line the same as the C++ example.
> 
> Any guidance would be greatly appreciated.
> 
> cheers,
> 
> Brucey

Make sure you call update() on the widget instead of calling the 
paintEvent() directly.

--
Samuel



More information about the Qt-interest-old mailing list