[Interest] Bug in Qt 4.8.5 (Windows/VS2010SP1): QPainter::drawRect() draws triangle instead of rect

Rainer Wiesenfarth Rainer_Wiesenfarth at trimble.com
Tue Apr 8 11:54:08 CEST 2014


(filed at Digia as INC-205425)

The following code should show a black rectangle on a white background. 
However, on startup it shows something that might be a triangle (it is 
clipped to the window extent). If you increase the widgte size in X, as 
soon as the lower right corner of the rect is visible, the drawing is ok 
(and will stay so if you make the window smaller again).

I observed this problem with Qt 4.8.5 on Windows using VS2010SP1, and I 
_think_ I saw it on Linux, too (can't reproduce atm). The problem does 
not show with Qt 4.7.3.

A workaround is to draw the four lines instead of the rectangle. 
However, for filled rectangles you also have to draw the rect (with pen 
Qt::NoPen) to get the interior. Strange enough, the filling works ok...

Code to reproduce:

-----8<---- main.cpp ----- 8<-----
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtGui/QPainter>
#include <QtCore/QRect>

class DrawingWidget : public QWidget
{
public:
     DrawingWidget () : QWidget ()
     { }

protected:
     virtual void paintEvent (QPaintEvent *)
     {
         QPainter    p (this);
         QRect       r;

         r.setCoords (100, -200, 1000, 200);
         p.fillRect (0, 0, width (), height (), Qt::white);
         p.setPen (Qt::black);
         p.drawRect (r);
     }
};


int main (int argc, char *argv[])
{
     QApplication    app (argc, argv);
     DrawingWidget   dw;

     dw.resize (300, 300);
     dw.show ();
     return app.exec();
}
-----8<---- EO main.cpp ----- 8<-----

-----8<---- rectDraw.pro ----- 8<-----
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .

# Input
SOURCES += main.cpp
-----8<---- EO rectDraw.pro ----- 8<-----

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

-- 
Software Engineer | Trimble Imaging Division
Rotebühlstraße 81 | 70178 Stuttgart | Germany
Office +49 711 22881 0 | Fax +49 711 22881 11
http://www.trimble.com/imaging/ | http://www.inpho.de/

Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim
Eingetragen beim Amtsgericht Darmstadt unter HRB 83893,
Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4282 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140408/801c28fc/attachment.bin>


More information about the Interest mailing list