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.

Task-number: QTBUG-37504

Change-Id: I932f8efdb4764e9b1eea84c802bf7e8718338e1d
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
Friedemann Kleint 2014-03-13 14:10:09 +01:00 committed by The Qt Project
parent 9ceeaaac79
commit 176342e70a
3 changed files with 16 additions and 15 deletions

View File

@ -626,14 +626,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

View File

@ -346,6 +346,19 @@ QString QWindowsXPStylePrivate::themeName(int theme)
QString();
}
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.
@ -1548,13 +1561,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));

View File

@ -350,6 +350,7 @@ public:
static HTHEME createTheme(int theme, HWND hwnd);
static QString themeName(int theme);
static inline bool hasTheme(int theme) { return theme >= 0 && theme < NThemes && m_themes[theme]; }
static bool isItemViewDelegateLineEdit(const QWidget *widget);
QIcon dockFloat, dockClose;