[Issue N8817] (Regression in Qt-3.1-beta2) Bug in QPainter::setClipRegion

qt-bugs at trolltech.com qt-bugs at trolltech.com
Wed Oct 23 10:01:55 BST 2002


Hi David,

fixed now. Was a bug in QRegion::setRects() that occured since we
completely rewrote the QRegion internals (to get around the 16 bit
limitations we had there before).

Feel free to check it into qt-copy :)

Cheers,
Lars


==== //depot/qt/main/src/kernel/qregion_x11.cpp#83 (text) ====

@@ -2790,13 +2790,29 @@
                and X as the minor sort key.
    </ul>
   \internal
-  Only some platforms have that restriction (QWS).
+  Only some platforms have that restriction (QWS and X11).
 */
 void QRegion::setRects( const QRect *rects, int num )
 {
     *this = QRegion( FALSE );
+    if ( !rects || (num == 1 && rects->isEmpty()) )
+       num = 0;
+
     data->region->rects.duplicate( rects, num );
     data->region->numRects = num;
+    if ( num == 0 ) {
+       data->region->extents = QRect();
+    } else {
+       int left = INT_MAX, right = INT_MIN, top = INT_MAX, bottom =
INT_MIN;
+       int i;
+       for ( i = 0; i < num; i++ ) {
+           left = QMIN( rects[i].left(), left );
+           right = QMAX( rects[i].right(), right );
+           top = QMIN( rects[i].top(), top );
+           bottom = QMAX( rects[i].bottom(), bottom );
+       }
+       data->region->extents = QRect( QPoint(left, top), QPoint(right,
bottom) );
+    }
 }

 /*!



On Friday, 11 Oct 2002 19:23 David Faure wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The standalone testcase below shows a new bug in Qt-3.1-beta2
> (compared to a 3.0.6-snapshot, I don't know about Qt-3.1-beta1).
>
> This program pops up a widget that should paint a red rectangle of
> size 60x60,
> at (100,100) (due to the painter translation).
>
> In Qt-3.1-beta2 it doesn't show up initially, one has to resize the
> window to see
> it appear (even simply moving another window on top, to force a
> repaint, doesn't
> work).
>
> Works without the translate() call, works without the
> setClipRegion()... This is why
> I'm suspecting the bug is in the setClipRegion call somehow.
>
>
> #include <qapp.h>
> #include <qpainter.h>
> #include <qwidget.h>
>
> class MyWidget : public QWidget
> {
> public:
>   MyWidget() : QWidget() {}
>   virtual void paintEvent( QPaintEvent * ) {
>       QPainter painter( this );
>       QRect r( 0, 0, 60, 60 );
>       QRegion reg( r );
>       reg -= QRect( 10, 10, 40, 40 ); // not necessary, but explains
>       why this setClipRegion/fillRect approach is used
>       painter.translate( 100, 100 );
>       painter.setClipRegion( reg, QPainter::CoordPainter );
>       painter.fillRect( reg.boundingRect(), QBrush( Qt::red ) );
>   }
> };
>
> int main ( int argc, char **argv)
> {
>     QApplication a(argc, argv);
>     QWidget * w = new MyWidget();
>     a.setMainWidget(w);
>     w->show();
>     return a.exec();
> }
>
> - --
> David FAURE, david at mandrakesoft.com, faure at kde.org
> http://people.mandrakesoft.com/~david/
> Contributing to: http://www.konqueror.org/, http://www.koffice.org/
> Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
>
> iD8DBQE9pwkO72KcVAmwbhARAhW4AKCnaxPyrcV2j2ek4WHxBf8PqGoDyQCbBptZ
> KhN9LB1Jx0JQVrNB7zwdoIE=
> =Aa+L
> -----END PGP SIGNATURE-----
>

--
Lars Knoll, Software Engineer
Trolltech AS, Waldemar Thranes gt. 98, N-0175 Oslo, Norway





More information about the kde-core-devel mailing list