[vtkusers] QWidget::paintEvent(..) Bug on Windows?
Jens Henrik Goebbert
jens.goebbert at post.rwth-aachen.de
Fri Apr 22 06:57:17 EDT 2005
Hi Trolltech
As Clinton Stimpson already wrote, there is a bug with QWidget::paintEvent(..)
on Windows (not no X11) when impementing a paintEvent like this:
virtual void paintEvent(QPaintEvent*)
{
::BeginPaint(this->winId(), &ps);
HDC dc = GetDC(this->winId());
::SetRect(&box, 0,0, width(), height());
::FillRect(dc, &box, brush);
::EndPaint(this->winId(), &ps);
}
Here what he wrote:
Below is a Windows app to demonstrate the problem.
If I step through the code with a debugger, the widget is correctly
painted blue when EndPaint() is called.
But when I step out of the paintEvent function, Qt appears to erase the
widget. So I never see any blue on my widget except when I'm stepping
through the code.
I've also seen similar problems when resizing where artifacts from
toolbars show up after paintEvent is called for my custom widget --
although this example doesn't demonstrate that problem.
Bye
Jens HEnrik
The demonstration app works fine in Qt3 and Qt4/X11, but doesn't work with
Qt4/Windows.
=====================================
#include <qapplication.h>
#include <qmainwindow.h>
#include <qpainter.h>
#include <windows.h>
class MyCustomWidget : public QWidget
{
HBRUSH brush;
PAINTSTRUCT ps;
RECT box;
public:
MyCustomWidget(QWidget* parent) : QWidget(parent)
{
brush = ::CreateSolidBrush(0x00FF0000); // blue
};
~MyCustomWidget()
{
::DeleteObject(brush);
}
virtual void paintEvent(QPaintEvent*)
{
::BeginPaint(this->winId(), &ps);
HDC dc = GetDC(this->winId());
::SetRect(&box, 0,0, width(), height());
::FillRect(dc, &box, brush);
::EndPaint(this->winId(), &ps);
}
};
int main( int argc, char* argv[] )
{
QApplication app(argc, argv);
QMainWindow window;
MyCustomWidget* widget = new MyCustomWidget( &window );
window.setCentralWidget( widget );
window.show();
return app.exec();
}
More information about the vtkusers
mailing list