Remove warning about non existing paint device engine
authorTitta Heikkala <titta.heikkala@digia.com>
Thu, 16 Aug 2012 08:27:57 +0000 (11:27 +0300)
committerQt by Nokia <qt-info@nokia.com>
Tue, 21 Aug 2012 06:58:40 +0000 (08:58 +0200)
The QWindowsVistaStyle::drawPrimitive() method was trying to draw the
pixmap for an item in an item view even if the section width was zero
or less then zero. This resulted "QPainter::begin: Paint device
returned engine == 0, type: 2" error.
It's now checked that the width and the height of the section is
greater than zero before creating the painter.

Task-number: QTBUG-26047
Change-Id: I36dd2792fd505be773951e5ac36b0e3362ec2292
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/widgets/styles/qwindowsvistastyle.cpp

index bcb24db..edc5079 100644 (file)
@@ -787,33 +787,35 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt
                 }
 
                 if (hover || selected) {
-                    QString key = QString::fromLatin1("qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
-                                                        .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
-                    if (!QPixmapCache::find(key, pixmap)) {
-                        pixmap = QPixmap(sectionSize);
-                        pixmap.fill(Qt::transparent);
-
-                        int state;
-                        if (selected && hover)
-                            state = LISS_HOTSELECTED;
-                        else if (selected && !active)
-                            state = LISS_SELECTEDNOTFOCUS;
-                        else if (selected)
-                            state = LISS_SELECTED;
-                        else
-                            state = LISS_HOT;
-
-                        QPainter pixmapPainter(&pixmap);
-                        XPThemeData theme(0, &pixmapPainter,
-                                          QWindowsXPStylePrivate::TreeViewTheme,
-                            LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
-                        if (d->initTreeViewTheming() && theme.isValid()) {
-                            d->drawBackground(theme);
-                        } else {
-                            QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget);
-                            break;;
+                    if (sectionSize.width() > 0 && sectionSize.height() > 0) {
+                        QString key = QString::fromLatin1("qvdelegate-%1-%2-%3-%4-%5").arg(sectionSize.width())
+                                                            .arg(sectionSize.height()).arg(selected).arg(active).arg(hover);
+                        if (!QPixmapCache::find(key, pixmap)) {
+                            pixmap = QPixmap(sectionSize);
+                            pixmap.fill(Qt::transparent);
+
+                            int state;
+                            if (selected && hover)
+                                state = LISS_HOTSELECTED;
+                            else if (selected && !active)
+                                state = LISS_SELECTEDNOTFOCUS;
+                            else if (selected)
+                                state = LISS_SELECTED;
+                            else
+                                state = LISS_HOT;
+
+                            QPainter pixmapPainter(&pixmap);
+                            XPThemeData theme(0, &pixmapPainter,
+                                              QWindowsXPStylePrivate::TreeViewTheme,
+                                LVP_LISTITEM, state, QRect(0, 0, sectionSize.width(), sectionSize.height()));
+                            if (d->initTreeViewTheming() && theme.isValid()) {
+                                d->drawBackground(theme);
+                            } else {
+                                QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget);
+                                break;;
+                            }
+                            QPixmapCache::insert(key, pixmap);
                         }
-                        QPixmapCache::insert(key, pixmap);
                     }
 
                     if (vopt->showDecorationSelected) {