PDA

View Full Version : How can i add some description about current QtreeWidgetItem inside QtreeWidgetItem



vinayaka
2nd March 2012, 10:19
Hai,
I need to display some icons and information when click on current QtreeWidgetItem



ex: code


for(int i=0; i<10; i++)
{
QStringList strings;
strings << QString("Wit Name");
QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
ui->secTreeWidget->addTopLevelItem(parent);
// Add the child TreeWidgetItem one step down in the tree
QTreeWidgetItem *child = new QTreeWidgetItem;
parent->addChild(child);
// Set the widget for the child item to be a QLineEdit for column zero.
ui->secTreeWidget->setItemWidget(child, 0, new QLabel(ui->secTreeWidget));
}

high_flyer
2nd March 2012, 10:40
What is the question?

vinayaka
2nd March 2012, 11:35
When we click on an item we need to display some lines of text and symbols below the clicked item.

high_flyer
2nd March 2012, 11:47
I asked what is the question, and you tell me what you want to do - that is not a question, but an assertion.
What is the problem you are having?
What do you mean "below the clicked item"?
Should it be part of the item?
Should it be in the tree context?
Do you mean like a tooltip maybe?
If you want help, provide enough information to help you.

Jonny174
2nd March 2012, 11:50
...
connect( tree, SIGNAL(clicked(QModelIndex)), this, SLOT(slotShowProp(QModelIndex)) );
...
slotShowProp( QModelIndex index )
{
index.data( Qt::DisplayRole ); - text
index.data( Qt::DecorationRole ); - icon
etc..........
}

vinayaka
2nd March 2012, 12:04
7461
We need to display some contents (some text and symbols)below the Wit Name


sample code is below:

for(int i=0; i<3; i++)
{
QStringList strings;
strings << QString("Wit Name");
QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
ui->firstTreeWidget->addTopLevelItem(parent);

parent->setIcon( 0, QPixmap::fromImage( QImage("images/heart.png") ) );

// Add the child TreeWidgetItem one step down in the tree
QTreeWidgetItem *child = new QTreeWidgetItem();
parent->addChild(child);
// Set the widget for the child item to be a QLineEdit for column zero.
ui->firstTreeWidget->setItemWidget(child, 0, new QLabel(ui->firstTreeWidget));
}
for(int i=0; i<1; i++)
{
QStringList strings;
strings << QString("Wit Name");
QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
ui->secTreeWidget->addTopLevelItem(parent);
// Add the child TreeWidgetItem one step down in the tree
QTreeWidgetItem *child = new QTreeWidgetItem;
parent->addChild(child);
// Set the widget for the child item to be a QLineEdit for column zero.
ui->secTreeWidget->setItemWidget(child, 0, new QLabel(ui->secTreeWidget));
}
for(int i=0; i<5; i++)
{
QStringList strings;
strings << QString("Wit Name");
QTreeWidgetItem *parent = new QTreeWidgetItem(strings);
ui->thirdTreeWidget->addTopLevelItem(parent);
// Add the child TreeWidgetItem one step down in the tree
QTreeWidgetItem *child = new QTreeWidgetItem;
parent->addChild(child);
// Set the widget for the child item to be a QLineEdit for column zero.
ui->thirdTreeWidget->setItemWidget(child, 0, new QLabel(ui->thirdTreeWidget));
}

high_flyer
2nd March 2012, 13:03
So you want to add children to WitName - but it seems you know how to do that, based on the code you posted.
So what is the problem?

vinayaka
2nd March 2012, 13:16
yes.. need to add children to Wit Name,also we need to add some symbols and text below the Wit Name.The following image is our expected Ui Design.Please see the image.I expect your valuable suggestions for creating the same.

high_flyer
2nd March 2012, 13:21
Why don't you answer my questions?

vinayaka
2nd March 2012, 13:37
Sorry..Problem is not able to add some text and Symbols below the Wit name.How can I add this?
Its part of the current Wit Name.Its not a tool tip.

high_flyer
2nd March 2012, 15:11
I am not sure that I follow - you just add new tree (child) items - and your code is doing that already (you just are not specifying any content to the labels in the items so they are empty) ...
Either I don't understand you, or you don't understand the code you posted - it already does what you want (as I understand you correctly), you just have to populate it with the data you want displayed.

d_stranz
3rd March 2012, 22:21
I am not sure that I follow - you just add new tree (child) items - and your code is doing that already (you just are not specifying any content to the labels in the items so they are empty) ...
Either I don't understand you, or you don't understand the code you posted - it already does what you want (as I understand you correctly), you just have to populate it with the data you want displayed.

I think the problem is that the OP wants to display more than just a line of text; it isn't just as simple as adding a new child item to the tree.

@vinayaka: Look at QTreeWidget::setItemWidget(). If you create a custom widget that contains what you want (labels, text, etc.), you can then set that at the appropriate place in your tree. When that node in the tree is opened, the widget will be displayed.

I am sure you will need to change the contents at run time, since it looks like you are trying to display dynamic contents. So also look at using QTextEdit as the item widget. You will format your text and other information (like symbols and hyperlinks) using the QTextDocument controlled by the QTextEdit.

This will not be simple to do, but then you are asking for a UI that is not simple. And no, I cannot provide you with example code. The Qt documentation contains several tutorials and examples on how to use QTextDocument and QTextEdit.