i want to create a listview as the attachement,but i can't find any sample code ,could any one can help me:p
Attachment 4717
Printable View
i want to create a listview as the attachement,but i can't find any sample code ,could any one can help me:p
Attachment 4717
Have a look at QListView::setViewModeJust play in designer a little.
i can't get how to use it ,can you give me some sample code from the beginning to end ,thank you
Code:
#include <QtGui> int main(int argc, char * argv[]) { model->setData(model->index(0, 0), lv->style()->standardIcon(QStyle::SP_BrowserReload), Qt::DecorationRole); model->setData(model->index(0, 0), "Hello World!", Qt::DisplayRole); model->setData(model->index(1, 0), lv->style()->standardIcon(QStyle::SP_FileIcon), Qt::DecorationRole); model->setData(model->index(1, 0), "Goodbye World!", Qt::DisplayRole); lv->setModel(model); lv->show(); return a.exec(); }
Thanks ,you are so kind ,but when i do this as you taught me ,and i found the lable is editable ,how to set the label is not allowed to be edited;:o
Ohh come one, read the documentation
http://doc.qt.nokia.com/4.6/index.html
i have looked up for this problem in the QT Document ,but i can't find any solutions ,plz help me:cool:
What label?
You have to set the item flags, as needed:
Code:
model->item(0,0)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
i set the lable model as this below ,however ,the lable still can be edit,i can't find any properties to stop this!
when i double clicked the item ,the lable can be renamed
Code:
model->setData(model->index(0,0),tr("This is input well data file"),Qt::WhatsThisRole| Qt::ItemIsEditable);
If you dont want the item editable, shouldnt you be using NOT of Qt::ItemIsEditable ( ~Qt::ItemIsEditable) :rolleyes:
i using the code as this ,however,it did't display the lable ,and still can be edited:pCode:
model->setData(model->index(0, 0), tr("Well Data"), Qt::DisplayRole|~Qt::ItemIsEditable);
You have to set flags, not data.
Ginsengelf
As far as I remember, I guess the flags are stored in standard item with (Qt::UserRole - 1)
could you give me some more details ,thanks !
try this code: