I'm working on a style for KDE and I'm having a lot of trouble with that QToolBox.

I dug deep into KDE and Qt sources and docs and I know how to style a CE_ToolBoxTab --upto the limits imposed by Qt-- but there's something I don't know how to do: To get the index of the toolbox tab corresponding to the widget I'm painting. I need that index to adapt the drawing to the position of the tab, especially for the first and last tab.

I tried various way and the least stupid one IMHO is:

const QToolBox* tb = (const QToolBox*) widget;
int count = tb->count();
int index = tb->indexOf( (QWidget*)widget );
It's modelled on the way to get the index of a regular tab... but it doesn't work. index is always -1 as if widget doesn't exist.

Can someone explain what I'm doing wrong?

Please, don't hesitate to use very simple words and to call me a noob.