Simple class to do what i want.
After working on it for one and a half day I finally reached the headerview as I wanted it to be:
[img_assist|nid=127|title=headerview|desc=|link=node|align=center|width=551|height=131]
The amount of time I spent on it was caused by a couple of reasons:
- I wanted to have a widget with a maximized height, if there was more data it should add a scroll bar, but if it has less data, the widget should shrink.
- When clicked on a hyperlink (left and right mouse button), it should emit a signal telling me, so i can popup a composer or a context menu.
- when an address does not fit in the current width, it should wrap it.
So I examined a couple of options. First of was kurllabel, which is based on a QLabel. Which is almost perfect, except for the fact that it can only hold one address at a time. So I used that, made a kurllabel for each address and put it in a vbox. That wasted a lot of space, because you can sometimes put multiple addresses on one line without problem.
Next to that, i did not implement the scrollbars and maximum height, so receiving a message with 20 people on the cc list, made it impossible to read the body of the mail.
Next on the list was the kactivelabel. As you feed it html, wrapping and multiple addressess on a line is no broblem. It is based on a qtextbrowser, so it’s basically a full browser. One unsolvable problem for me was that the height of an kactivelabel is more than a qlabel and i could not find a way to reduce the spacing I saw. Besides that, using a browser for a simple label seemed a bit overkill to me.
Yesterday I switched back to a simple QLabel, as it is capable of displaying simple rich text, and that is all i need. Only a default QLabel does not emit signals when clicked on a link. I browsed a bit through the internals of a QLabel and found a class written by Waldo that makes use of a QSimpleRichText helper to determine the used width of a QLabel. I tried to do the same for determining if a there is a click on a link, because the QSimpleRichText class contains a anchorAt() function. And that worked.
And now I’ve the widget I wanted. Again a confirmation of the fact that 70% of the things take 30% of the time and 30% of the things take 70% of the time. Or was it 10% vs. 90%?