PDA

View Full Version : QTreeWidget::setItemWidget ( QTreeWidgetItem * item, int column, QWidget * widget )



merry
18th October 2010, 07:42
Hi

Working on Qt4.4 on my mac machine,

I used QLabel to display text in QTreeWidget by using setItemWidget, It works fine, but when I scroll QTreeWidget up or down, the item in the QLabel will disappear. What can I do when I scroll QTreeWidget up or down the item in the label will not dissapear.

Thanks

faldzip
18th October 2010, 08:32
First of all - why are you using QLabel to display text in QTreeWidget? Is there any special functionality of QLabel, which you need in your case? Did you try it in "normal" way without any widgets in view?

merry
18th October 2010, 08:57
I want to use formatted string - that is the string with two different fonts, thats why I used label, in which i will be able to display html text.

In normal way, without any widgets it is working fine.

But I have to use label.

merry
18th October 2010, 12:22
Pls reply is there any way , that on scrolling up down the treeWidget , QWidget will not dissappear.

faldzip
18th October 2010, 12:46
Using widgets in views is not recommended as it is slow and resource consuming, and views are not for widgets (layouts are). But sometimes widget functionality is needed in view, but in such simple case as yours (displaying rich text via QLabel) it is bad idea to you QLabel. I would suggest you implementing a delegate which draws your text in your own way. You can use QTextDocument in your case and it shouldn't be complicated.

merry
19th October 2010, 06:28
Thanks for the reply.

I tried to use QTextDocument parent QTextEdit, and by using this also on Scrolling treeWidget up down i still got the same problem.

Is there any other way that i can use html string in QTreeWidgetItem.

So that I can add that formatted text in QTreeWidgetItem.

Lykurg
19th October 2010, 07:57
can you provide a minimal compilable program reproducing your problem?

faldzip
19th October 2010, 08:32
Is there any other way that i can use html string in QTreeWidgetItem.
I already told you - create your own delegate, which will paint the formatted text. And for painting you can use QTextDocument. It has its nice method QTextDocument::drawContents().

I tried to use QTextDocument parent QTextEdit
you don't need any QTextEdit there.

EDIT:
It is not that hard. The example which is shown below took 60 lines of code, where main() is almost half of it and is just adding items :P