From 70b97f4090d2469b430f24b02672eaa22c819528 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 14 Mar 2014 10:34:08 +0100 Subject: [PATCH] WIP: QWindowsXP/VistaStyle: Fix detection of item view delegate line edits. The old code tried to check the 2nd parent for inheritance from QAbstractItemView. This also triggers for line edits on a QDialog parented on the item view. Introduce convenience function that checks for top levels in the chain. TODO: Do not submit as is, should be cherry-picked from https://codereview.qt-project.org/#change,80845 Task-number: QTBUG-37504 --- src/gui/styles/qwindowsvistastyle.cpp | 9 +-------- src/gui/styles/qwindowsxpstyle.cpp | 21 ++++++++++++++------- src/gui/styles/qwindowsxpstyle_p.h | 2 ++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/gui/styles/qwindowsvistastyle.cpp b/src/gui/styles/qwindowsvistastyle.cpp index abe729b..c380dc7 100644 --- a/src/gui/styles/qwindowsvistastyle.cpp +++ b/src/gui/styles/qwindowsvistastyle.cpp @@ -646,14 +646,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt anim->paint(painter, option); } else { QPainter *p = painter; - QWidget *parentWidget = 0; - if (widget) { - parentWidget = widget->parentWidget(); - if (parentWidget) - parentWidget = parentWidget->parentWidget(); - } - if (widget && widget->inherits("QLineEdit") - && parentWidget && parentWidget->inherits("QAbstractItemView")) { + if (QWindowsXPStylePrivate::isItemViewDelegateLineEdit(widget)) { // we try to check if this lineedit is a delegate on a QAbstractItemView-derived class. QPen oldPen = p->pen(); // Inner white border diff --git a/src/gui/styles/qwindowsxpstyle.cpp b/src/gui/styles/qwindowsxpstyle.cpp index f65fd79..99ec5d6 100644 --- a/src/gui/styles/qwindowsxpstyle.cpp +++ b/src/gui/styles/qwindowsxpstyle.cpp @@ -287,6 +287,19 @@ void QWindowsXPStylePrivate::cleanupHandleMap() handleMap = 0; } +bool QWindowsXPStylePrivate::isItemViewDelegateLineEdit(const QWidget *widget) +{ + if (!widget) + return false; + const QWidget *parent1 = widget->parentWidget(); + // Exlude dialogs or other toplevels parented on item views. + if (!parent1 || parent1->isWindow()) + return false; + const QWidget *parent2 = parent1->parentWidget(); + return parent2 && widget->inherits("QLineEdit") + && parent2->inherits("QAbstractItemView"); +} + /*! \internal This function will always return a valid window handle, and might create a limbo widget to do so. @@ -1466,13 +1479,7 @@ case PE_Frame: } case PE_FrameLineEdit: { // we try to check if this lineedit is a delegate on a QAbstractItemView-derived class. - QWidget *parentWidget = 0; - if (widget) - parentWidget = widget->parentWidget(); - if (parentWidget) - parentWidget = parentWidget->parentWidget(); - if (widget && widget->inherits("QLineEdit") - && parentWidget && parentWidget->inherits("QAbstractItemView")) { + if (QWindowsXPStylePrivate::isItemViewDelegateLineEdit(widget)) { QPen oldPen = p->pen(); // Inner white border p->setPen(QPen(option->palette.base().color(), 1)); diff --git a/src/gui/styles/qwindowsxpstyle_p.h b/src/gui/styles/qwindowsxpstyle_p.h index 13d0c94..91560ce 100644 --- a/src/gui/styles/qwindowsxpstyle_p.h +++ b/src/gui/styles/qwindowsxpstyle_p.h @@ -321,6 +321,8 @@ public: bool fixAlphaChannel(const QRect &rect); bool swapAlphaChannel(const QRect &rect, bool allPixels = false); + static bool isItemViewDelegateLineEdit(const QWidget *widget); + QRgb groupBoxTextColor; QRgb groupBoxTextColorDisabled; QRgb sliderTickColor; -- 1.8.3.msysgit.0