PDA

View Full Version : To add QTreeWidgetItem with two Stringsand with different fonts in a QTreeWidgetItem.



merry
23rd September 2010, 11:30
Hi,

I am working on Qt4.3.4 on my mac . I want to add an item in QTreeWidget , but QTreeWidgetItem should contain two strings - One String is of greater font than the other and other string is in next line and of smaller font, and also how to get the value of the second string. Image file is attached, for the reference. I want to add item in the QTreeWidget in the way it is in the File Attached.

Thanks,

Lykurg
23rd September 2010, 11:58
You have two possibilities: a) use a custom delegate (recommended option) b) use QTreeWidget::setItemWidget().

merry
23rd September 2010, 12:27
Thanks for the reply. Can you pls explain it with an example.....how can i use custom delegate.

Lykurg
23rd September 2010, 13:53
A starting point is "Model/View Programming! in the docs. If you have a more specific question, ask again.

merry
23rd September 2010, 14:35
Yaa actually I had two strings eg. "String1" and "String2" I had inserted these strings in a QTreeWidget


QTreeWidget *treeWidget = new QTreeWidget(this);
QTreeWidgetItem *item1 = new QTreeeWidgetItem(treeWidget);
item1->setText(0,"String1");
tem1->setFont(0,font1);
QTreeWidgetItem *item2 = new QTreeeWidgetItem(item1);
item2->setText(0,"String2");
tem1->setFont(0,font2);

The output is:

String1
String2

String1 is the parent of String2 and treeWidget is parent of String1

But I want both the strings should be of the same parent, but should be split and with the different fonts. That I had shown in the Attached file.

Lykurg
23rd September 2010, 14:58
Please use the [code] tags next time. And in your code I can't see a custom delegate nor setItemWidget(). So if you don't try what I suggest you, I really can't help you. I won't provide a ready to use solution!