Hello,
I need a little help getting a QTreeView to display some characters. Let me first say that I'm not a very good programmer and pretty new to QT.
I am trying to make a QTreeView which behaves like a multi-column QListView used to in qt3 (btw, why are columns no longer available in QListView? It doesn't seem necessary for the model/view-thing to remove them). My first question is just if this is basically correct. Here is my QTreeView code, I mostly pieced it together from examples:
Code:
#include <QtGui> int main(int argc, char *argv[]){ qtv->setItemsExpandable(false); qtv->setRootIsDecorated(false); qtv->setUniformRowHeights(true); qtv->setSortingEnabled(true); qtv->sortByColumn(0, Qt::AscendingOrder); for (int i = 0; i < 5; ++i) for (int j = 0; j < 3; ++j) itemmodel->setItem(i, j, new QStandardItem(QString("Row: ") + QString::number(i) + QString(", Column: ") + QString::number(j))); qtv->setModel(itemmodel); qtv->show(); return app.exec(); }
Now (though it might not be the proper or most efficient way to do it) this seems to do what I want it to. But when I put a string in like "Eléna" in the model using itemmodel->setItem(i, j, new QStandardItem(QString("Eléna"))), the treeview shows "Eléna" instead. If I access the text in the model using itemmodel->item(i,j)->text() it does show the correct text. I had this problem in qt3 as well, I just thought while I was learning qt4, I might as well get this out of the way too. So could someone please help me fix this?
Thanks,
bepaald