Styled custom widgets

Thomas Lübking thomas.luebking at web.de
Tue Sep 2 12:29:04 BST 2008


Am Saturday 30 August 2008 schrieb Girish Ramakrishnan:
> See you point but they cannot be added to Qt since it breaks BC. This
> might be a problem from KStyle too. Of course, we can always ask them
> add it as slots :-)).
Humm... don't know about the BC impact, but at least the atom generating 
function does not necessarily have to be part of QStyle or anyclass (it's an 
app wide global stytic value anyway)
so "int qt_primitive_element_atom(const &QString)" instead of "static int 
QStyle::primitiveElement(const QString &)" would be fine as well (and i guess 
updating the doc /is/ allowed ;-P )

if it's not possible to add it to any "public" header, one could even just 
#ifdef the Qt version and "extern int qt_primitive_element_atom(const 
&QString)" - though this is probably less reliable...

Together with the - yes, less simpler - QList<int> approach we would then 
really have runtime addable style elements... yesno?!

for formal procedure:
Marksim or Sandro, is one of you the proper person to coordinate this with 
TrollTech (it'd probably be good to have such function directly in Qt) and add 
it somewhere in KDE in case they say nay?
(Means: what should one do to maximize the odds to get it in?)

--- some reply text to get a rough idea if you read for the first time ---

> > I suggest to reserve the area > 0xff000000 (0xf0000000 is *_CustomBase,
> > meaning that every smartass will use 0xf0000001, 0xf0000002 a.s.o. for
> > their application specific elements - in case there are...) and abuse
> > QStyle::styleHint() to ask styles for support, like
> > #define SH_SupportedPrimitives 0xff000001
> > #define SH_SupportedConltrols 0xff000002
> > #define SH_SupportedComplexConrols 0xff000003
> >
> > QStyle::styleHint() returns '0' (i.e. false...) by default and also
> > supports QVariants (including QList<int> ...) as returndata.
> > So on constructing the widget and QEvent::StyleChange one could query and
> > cache the support by e.g.
> > QList<int> styleSupportedPrimitives;
> > style()->styleHint(SH_SupportedPrimitives, 0, this,
> > &styleSupportedPrimitives);
> > this->supportedByStyle =
> > styleSupportedPrimitives.contains((int)KStyle::PE_WhatEver);
>
> Another approach would be to add a SH_SupportsXXX for every PE_XXX or
> CE_XXX. Providing a QList<int> feels very powerful but I really doubt
> its usefulness beyond this use case (also one has to concat this list
> with the parent style's list and all that). Instead,
>
> if (style()->styleHint(SH_SupportsXXX)) {
>     style()->drawControlElement(CE_XXX);
> } else {
>     // fall back painting
> }
>

Thomas





More information about the kde-core-devel mailing list