Qt-jambi-interest Archive, December 2007
Jambi Custom Widgets and Styles
Message 1 in thread
I am trying to create a new custom widget by extending
QTreeView called MyCustomTree. I am putting the custom
widget in a dialog and try to customize the whole
window using window.setStyleSheet( sStyle )
My sStyle looks like:
MyCustomTree {
......
}
This doesn't work, it doesn't apply the style to the
custom widget in the window. However, if I have the
sStyle set for the base component QTreeView it works:
QTreeView {
.....
}
I want to find a way to use styles on my custom
widgets based on the class name. Is this possible ?
Thanks,
Danny
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
Message 2 in thread
Hi Danny Sporea
On Wednesday 19 December 2007 22:57, Danny Sporea wrote:
> I am trying to create a new custom widget by extending
> QTreeView called MyCustomTree. I am putting the custom
> widget in a dialog and try to customize the whole
> window using window.setStyleSheet( sStyle )
>
> My sStyle looks like:
>
> MyCustomTree {
> ......
> }
>
> This doesn't work, it doesn't apply the style to the
> custom widget in the window. However, if I have the
> sStyle set for the base component QTreeView it works:
When you create a custom widget in Qt Jambi you will get a new class in Java
but not in c++. So on the c++ side it will just look like another
QTreeWidget. Each class on the c++ side has a meta object giving us
introspection, and this is what is used by the style sheet system. Therefor
this will not work before we create a "fake meta object" for the objects that
are instantiated from a custom class on the Java side.
In Qt Jambi 4.4 Eskil has just done this, and you can read his blog about it:
http://labs.trolltech.com/blogs/2007/12/12/qt-jambi-doth-teach-the-torches-to-burn-bright/
So before 4.4 you will not be able to do this the way you tried to do it, but
it will work in 4.4 :-)
As you said, making a stylesheet for QTreeWidget worked, but you only wanted
them to be set on your custom widgets. You can try this as a workaround:
In the constructor you will call the function.
widget.setObjectName("MyCustomTree");
Then in your style sheet you can reference all the objects created like this
with:
QTreeWidget#MyCustomTree { background: yellow }
This should apply the style sheet to all classes of type QTreeWidget with the
name MyCustomTree.
Hope this will work for as a workaround for you until 4.4
>
> QTreeView {
> .....
> }
>
> I want to find a way to use styles on my custom
> widgets based on the class name. Is this possible ?
This is not possible before the 4.4 release.
>
> Thanks,
> Danny
>
>
Best regards
Håvard Frøiland
>
> ___________________________________________________________________________
>_________ Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ