PDA

View Full Version : QToolBox and style



Maxilys
23rd February 2006, 04:24
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. ;)

jacek
23rd February 2006, 11:27
const QToolBox* tb = (const QToolBox*) widget;
int count = tb->count();
int index = tb->indexOf( (QWidget*)widget );
It looks like you are trying to get the index of the toolbox itself (widget == tb). In the third line you should use the variable that points to the tab instead of widget.

Maxilys
23rd February 2006, 18:32
I know, the third line is, well, circular. I read Qt sources a little too quickly. widget is in fact the parent of the toolbox tab I have to draw.

Now, the question is: How can I find the widget I'm actually drawing with the few informations I have? All I know for sure is the parent widget and the containing rectangle of the widget I'm looking for. That's not much.

I thought that this code should be a step in the right direction:


int index = tb->indexOf( tb->childAt(left,top) );

But it doesn't work either. I also tried childAt( r.center() ), all the available mappings although Qt docs don't said any should be necessary. It made no difference.

The noob I am needs a much bigger push in the right direction... ;)

wysota
24th February 2006, 10:45
Maybe you should try peeking Qt sources to see if the default styles use something simmilar?

Maxilys
24th February 2006, 16:00
I wish it was that simple! Reading Qt and KDE sources is my first move to find the limitations of what I can do. Next, I read what some other styles do.

In this case, nobody cares about QToolBox except Qt... and the default style draws all the toolbox tabs the same way unless it's selected. Useless. :(

I'm gonna ask to the KDE Dev list --if they're not too busy-- then I'll go to the real source of Qt: the Trolls of Trolltech. I've been told they know a little more about Qt than anybody. ;)

Brandybuck
23rd March 2006, 04:05
I styled the QToolBox widget in my Phase style, included in kdeartwork. It was written for Qt3. I don't know how well the KDE4 porting guys did moving it to Qt4. Anyway, it's there and hopefully easy to understand.

Maxilys
26th March 2006, 16:07
I styled the QToolBox widget in my Phase style, included in kdeartwork. It was written for Qt3. I don't know how well the KDE4 porting guys did moving it to Qt4. Anyway, it's there and hopefully easy to understand.

That's right you styled the QToolBox but you just reproduced the Qt look and there is no mouseover effect on the tooltabs. But it doesn't matter. Look at my QToolbox (http://home.tele2.fr/mxls/archives/ToolBoxTabs.png). I think I can leave it this way until Qt5 (and I mean 5, not 4) since there is no improvement of the QToolBox in Qt4. "They" just adapted the source but the widget's handling is unchanged. So... Let's forget about it.

If I'm saying "thank you" that's because your style gave me some answers to some problems I have with my style... and the source is legible. I'm gonna schedule a meeting with my friends Cut & Paste. ;)