PDA

View Full Version : 3 questions about QTreeView



Guilo
10th February 2010, 20:38
Hi !

First of all, what is the difference between QTreeView and QTreeWidget ? The same applies for QListView and QListWidget.

I want the first column of my QTreeView to display a checkbox. Here is my code :

QStandardItem* item0 = new QStandardItem();
item0->setCheckable(true);
item0->setCheckState(Qt::Checked);
item0->setAccessibleText(false);
item0->setEditable(false);

It works great but I have seeked for how to center the checkbox in the column and didn't find anything. There is no text in that column, only a checkbox.

And finally, I wonder how to add a combox in my tree and even if it is possible within a QTreeView. I don't especialy need a QTreeView, only a "list"-style widget.

Thanks

Lykurg
10th February 2010, 21:06
First of all, what is the difference between QTreeView and QTreeWidget ? The same applies for QListView and QListWidget.
The first is to use with a model, the second is item based. Read the docs about Model/View programming.


I want the first column of my QTreeView to display a checkbox. Here is my code :

QStandardItem* item0 = new QStandardItem();
item0->setCheckable(true);
item0->setCheckState(Qt::Checked);
item0->setAccessibleText(false);
item0->setEditable(false);

It works great but I have seeked for how to center the checkbox in the column and didn't find anything. There is no text in that column, only a checkbox.

if inside a view: see your delegate.



And finally, I wonder how to add a combox in my tree and even if it is possible within a QTreeView. I don't especialy need a QTreeView, only a "list"-style widget.

Guess I don't understand your question: use QListView? And for the combo box: also see the item delegate or for a list widget: QListWidget::setItemWidget().