i want to create a listview as the attachement,but i can't find any sample code ,could any one can help me
未命名..jpg
i want to create a listview as the attachement,but i can't find any sample code ,could any one can help me
未命名..jpg
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
Qt 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(); }To copy to clipboard, switch view to plain text mode
xiongxiongchuan (3rd June 2010)
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;
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
What label?
You have to set the item flags, as needed:
Qt Code:
model->item(0,0)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);To copy to clipboard, switch view to plain text mode
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
Qt Code:
model->setData(model->index(0,0),tr("This is input well data file"),Qt::WhatsThisRole| Qt::ItemIsEditable);To copy to clipboard, switch view to plain text mode
Last edited by xiongxiongchuan; 5th June 2010 at 12:50.
If you dont want the item editable, shouldnt you be using NOT of Qt::ItemIsEditable ( ~Qt::ItemIsEditable)
i using the code as this ,however,it did't display the lable ,and still can be editedQt Code:
model->setData(model->index(0, 0), tr("Well Data"), Qt::DisplayRole|~Qt::ItemIsEditable);To copy to clipboard, switch view to plain text mode
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:
Qt Code:
To copy to clipboard, switch view to plain text mode
Bookmarks