int row = rowCount(); // number of folders already in the model
insertRow(row); // add a new row
QModelIndex ind
= index
(row,
0);
// index of the newly created item insertColumn(0, ind); // add a column for future children of the item
setData(ind, foldername.dirName(), Qt::DisplayRole);
return ind;
}
int row = rowCount(parent); // get number of files
insertRow(row, parent); // insert new file
setData(ind, file.completeBaseName(), Qt::DisplayRole); // insert filename in
setData(ind, file.absoluteFilePath(), Qt::UserRole); // insert full path in Qt
return ind;
}
setData(parent, image, Qt::UserRole+1);
return parent;
}
QModelIndex myModel::addFolder(const QDir &foldername){
int row = rowCount(); // number of folders already in the model
insertRow(row); // add a new row
QModelIndex ind = index(row, 0); // index of the newly created item
insertColumn(0, ind); // add a column for future children of the item
setData(ind, foldername.dirName(), Qt::DisplayRole);
return ind;
}
QModelIndex myModel::addFile(const QModelIndex &parent, const QFileInfo &file){
int row = rowCount(parent); // get number of files
insertRow(row, parent); // insert new file
QModelIndex ind = index(row, 0, parent); // get index
setData(ind, file.completeBaseName(), Qt::DisplayRole); // insert filename in
setData(ind, file.absoluteFilePath(), Qt::UserRole); // insert full path in Qt
return ind;
}
QModelIndex myModel::addImage(const QModelIndex &parent, const QPixmap &image){
setData(parent, image, Qt::UserRole+1);
return parent;
}
To copy to clipboard, switch view to plain text mode
void MainWindow
::changeItemInLV2(const QModelIndex &myIndex
){ imageLabel->setText(myIndex.sibling(myIndex.row(),0).data(Qt::UserRole).toString());
}
void MainWindow::changeItemInLV2(const QModelIndex &myIndex){
imageLabel->setText(myIndex.sibling(myIndex.row(),0).data(Qt::UserRole).toString());
}
To copy to clipboard, switch view to plain text mode
And how to create a method to get an image from Qt::UserRole+1 I can't understand.
Bookmarks