[PATCH] Fix infinite recursion in KdeuiWidgetsProxyStyle

Aurelien Gateau aurelien.gateau at free.fr
Fri Jun 13 08:57:46 BST 2008


David Faure wrote:

> On Wednesday 11 June 2008, Aurélien Gâteau wrote:
>> dynamic_cast<KLineEditStyle*>(style())
>> 
>> Would return 0 if the parent widget where using QStyleSheetStyle (I
>> haven't figured out why).
> 
> Well, because QWidget::setStyleSheet() sets the widget's style to be the
> QStyleSheetStyle, so obviously style() is a QStyleSheetStyle* and not a
> KLineEditStyle* anymore...
> 
> Anyway the klineedit.cpp change is fine, makes things more robust.

Except I forgot to init overlap to 0... Will commit an updated patch.
 
> The proxystyle change is, well, I'm happy you found a fix, but obviously
> it's not that robust; it uses the classname of an internal Qt class which
> could be renamed any day, or any other other similar proxy could end up
> creating the same trouble; it has a "fallback to windows style" last
> resort which sounds like it might create bugs... I wish Qt had real
> support for proxy styles and avoided the recursion in the first place. I
> still don't really understand why it recurses, normally proxies (e.g. in
> modelview) only call down in the stack, never up... Hmm isn't this because
> we use the style of the parentwidget of the lineedit, instead of simply
> storing the style which the lineedit itself was using, before setting our
> proxy? This would seem like a better approach for setting up the proxy
> style in a way that avoids the recursion, no? I mean passing the current
> style of the lineedit (if it's not a kdeuiproxystyle already) to the
> kdeuiproxystyle constructor.

I was puzzled with this, so I digged a bit further, to found out that when
you call setStyle() on a widget which is already using QStyleSheetStyle,
a new QStyleSheetStyle is created. Still I agree with what you told Olivier,
this should not recurse nevertheless.

For information, the recursion happens when QStyleSheetStyle calls
nativeFrameWidth(), which calls pixelMetric(), which instantiate a
QRenderRule, which calls pixelMetric()... it was too late yesterday evening
to dig into this further.

Proxy styles are a useful tool to have in our toolbox, it would be nice
if Qt featured a QProxyStyle, similar to KdeUiWidgetsProxyStyle. This
QProxyStyle could be kept aware of QStyleSheetStyle, or maybe
QStyleSheetStyle could even inherit from it.

As for the fallback to QWindowsStyle, you have to keep in mind that this
only happens if you are using an application-wide stylesheet, so it's quite
rare. I can change the code to fallback to QPlastiqueStyle, but falling back
to OxygenStyle will create a circular dependency on kdebase/runtime.

Aurélien





More information about the kde-core-devel mailing list