This document is now outdated. The QStyle API was changed in Qt 3, so if you want to write a widget style for KDE 3, this page isn’t too much use to you, except perhaps the tips at the end.
You can download a copy of this document and all related example code here:
KDE allows two methods of customising widget appearance.
A ‘code’ style is a shared library module, containing code which implements the virtual methods of KStyle (and QStyle.)
Advantages:
Disadvantages:
A pixmap theme consists of a set of pixmaps and a configuration file, which describes how the pixmaps will be arranged on-screen.
Advantages:
Disadvantages:
This tutorial will cover ‘code’ styles only. If you are not a programmer, please look at the tutorial on mosfet.org to learn how to create a pixmap theme.
If you are wanting to use a lot of pixmaps, you’re probably best off with a pixmap theme, nevertheless you may need more control than afforded by pixmap themes, so you are forced to write a ‘code’ style.
If you use pixmaps within a ‘code’ style, you will have to be careful with memory allocation, caching, etc. Good luck !
To begin the process of creating a widget style, you need to set up a build system and create some skeleton code which you can modify one piece at a time.
Fortunately for you, I’ve already done this bit. Unpack the tarball. In there you’ll find an example widget style called ‘web’, a skeleton implementation and a copy of this document.
cd skel_style ./setup MyStyle mystyle 'My style' 'A funky style'
‘setup’ does a simple search and replace, then renames some files to reflect the class name you provide.
The first parameter to setup is the name you want to use for your class.
The second parameter is the name you want to use for your library. Please use a string of lower-case letters, without punctuation, otherwise you might confuse automake.
The third parameter is the name of your style as it will be shown to the user (which will be translated later.) You can use spaces, as long as you put the text in ''.
The fourth parameter is the American English description of your style (which will be translated later.) You can use spaces, as long as you put the text in ''.
Now you should have a complete setup. Next steps:
make -f admin/Makefile.common ./configure --with-pic --enable-debug make install
Now your style should be installed and working. You can set your style as the default for all KDE apps started in future by using:
settheme src/MyStyle.themerc
If you’re having trouble with your style, you can go back to the default style like this:
settheme $KDEDIR/share/apps/kstyle/themes/default.themerc
You might notice that your style looks exactly like the low-colour default KDE style. That’s because all the method implementations simply call the KStyle:: versions.
This is where you start doing some work.
$EDITOR MyStyle.cpp
The plan: Replace some or all calls to KStyle in MyStyle.cpp with your own drawing code. How you paint is up to you - it’s your style !
$EDITOR WebStyle.cpp
The ‘web’ style is there for a reason. I wrote it especially to go with this tutorial. It uses simple drawing, which should give you a good base to work from, but it also uses a few tricks, so you can see how to achieve more flexibility. It has bugs, yes. I’ll try to fix them in the near future.
The last thing I can do to help those writing their first KDE widget style is to offer some tips, based on my experience.
Examples:
Please mail me if you find any errors in this tutorial or can improve on the example code (that shouldn’t be too hard ;) - If you can make this tutorial better, I’ll incorporate your changes.