Styled custom widgets

Thomas Lübking thomas.luebking at
Thu Sep 4 14:56:11 BST 2008

Am Thursday 04 September 2008 schrieb Girish Ramakrishnan:
> Well, instead of reserving enumerations in KStyle, you are now reserving
> strings. We need to make sure that strings used by different
> applications don't conflict. But that is easily overcome with a string
> format like "appname.element".

> As for your solution, at this point, I would like to point out adding
> support for custom widgets in QStyle is not about adding PE_X, CE_X
> enums. One needs to add support for querying element positions, hit
> testing, sizes etc (which involves adding more enums like SC_, CC_, SE_).
for complex widgets, yes...
currently i'd be happy to impat the look at all though ;-)

> Give that, you are going to have add support to query all the above
> dynamically.
semi-dynamically (as mentioned: on construction and style change is enough, if 
you expect many instances, you can also carry static QMap's<QStyle*, int> as 

> I still prefer the SH_SupportsXX approach :) but I don't
> really know about the release dynamics. So, if you still want to do a
> dynamic string -> enum lookup, I would suggest:
> 1. Make sure the strings are namespaced ("appname.widget")
> 2. Create,
>    struct KCustomWidgetStyleOption: public QStyleOption
>    {
>         QString widgetName;
>    };
>    struct KCustomWidgetHintReturn : public QStyleHintReturn
>    {
>        QList<int> primtiveElements; // well defined order
>        QList<int> subcontrolElements;
>        // .. and so on ..
>    };
>    In the widget,
>    style()->styleHint(SH_CustomWidget, &customWidgetStypeOption, this,
>                       &returnData);

That means, that widgets and style must be (silently) in accordance about the 
returndata, yesno? ("well defined order" i.e. what listelement means what?)
I fear this will fail... :-\
So if introducing a new styleoption 
struct KCustomWidgetStyleOption: public QStyleOption
    QString elementName; // SEE THIS LINE =D
is less trouble than playing with the widgetname, i'd prefer:

KCustomWidgetStyleOption opt;
opt.elementName = "amarok.CC_Analyzer";
d.styleElements.cc_analyzer = style()->styleHint(SH_CustomWidget, 
&customWidgetStypeOption, this);

	if (d.styleElements.cc_analyzer)

(btw: Qt calls a stylehint everytime you type into a secret echo box... and 
couple of times painting every push/tool-button - it's probably not that much 
overhead ;-)


More information about the kde-core-devel mailing list