PDA

View Full Version : Can i change QTreeWidget to a icon mode like QListWidget??



The_hero
29th May 2009, 14:31
I want to create a QTreeWidget or qlistview or qlistwidget, that can show some date as a list that have columns and can let the user clicke a button to change the style as a icon mode.

listWidget->insertItem(0, new QListWidgetItem(
QIcon("copy.png"), "caterpillar"));
listWidget->addItem("name");
listWidget->setViewMode(QListView::IconMode);
but listwidget i don't kwon how to add columns

treewidget i can add columns, but i can change list mode to icon mode

please help me! thank so much!

wysota
30th May 2009, 01:53
I'm not sure what you mean but you can control the looks of items by changing a delegate of the view.

The_hero
30th May 2009, 02:04
I want add a headitem like QTreeview's column in the Qlistview or Qlistwidget.
Sorry my english is not very good:)

wysota
30th May 2009, 02:07
It doesn't make much sense as QListView only has a single column so you won't see much but if you want then use QAbstractScrollArea::setViewportMargins() to "push" the contents of the viewport down and then you can place a QHeaderView there. Then you'll need to reimplement resizeEvent() for the list so that you can update the geometry of the header when the width of the list changes.

The_hero
30th May 2009, 02:16
how can i let the listview like this:
------------------------------------------------------------
|1 |2 |3 |4 |
------------------------------------------------------------
cloude english 18 male

faldzip
30th May 2009, 07:11
you can't because list view has a one column always. Just use QTreeView with only one level of items, so it will look like list, and you can have as many colums you want.

The_hero
31st May 2009, 11:21
But teacher ask we write a program that the list must have columns "name,age,department",and you can add information.It also can change to icon mode ro list mode (icon mode don't have columns)

how can i do that??

aamer4yu
31st May 2009, 11:30
As wysota said in #2,, delegates :)
Have a look at QItemDelegate and QStyledItemDelegate