jpn I appreciate your suggestion but can you give me some reasons and how you think that I should use the list view?Originally Posted by jpn
jpn I appreciate your suggestion but can you give me some reasons and how you think that I should use the list view?Originally Posted by jpn
Last edited by SkripT; 4th April 2006 at 12:15.
Because it's this simple:
Qt Code:
#include <QtGui> int main(int argc, char *argv[]) { // a "file manager" at simplest :) tree->setModel(model); list->setModel(model); list->setDragEnabled(true); splitter->show(); // tree navigation by click list, SLOT(setRootIndex(const QModelIndex&))); // list navigation by dbl click list, SLOT(setRootIndex(const QModelIndex&))); // update tree upon list change tree, SLOT(setCurrentIndex(const QModelIndex&))); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec(); }To copy to clipboard, switch view to plain text mode
Notice the amount of code..with this, you can already drag'n drop a file from the list view to e.g. desktop..
J-P Nurmi
Cool jpn thanks, where have you get this example? Is it from your creation?
No problem. Yep, I did it myself..
It's not a complete solution, just a small example demonstrating the power of QDirModel![]()
J-P Nurmi
Nice... is there any way you can go back to the parent of the "current" modelindex? Or does setRootIndex() overwrite everything "above" the defined index?
I am using a QTreeView with
view->setRootIsDecorated(false);
view->setItemsExpandable(false);
So I can only see the top level list.
Last edited by invictus; 4th November 2007 at 14:38.
You can get the parent via QModelIndex::parent(). If you want to provide a button with "go one level up" -functionality, the slot connected to button's SIGNAL(clicked()) would do roughly:
Qt Code:
view->setRootIndex(parent); button->setEnabled(parent.parent().isValid());To copy to clipboard, switch view to plain text mode
Last edited by jpn; 4th November 2007 at 16:12. Reason: spelling error
J-P Nurmi
jpn (4th November 2007)
hello all,
and what about providing custom class inherited from QFileIconProvider (QDirModel::setIconProvider()) that generates thumbnails? My app generates them in separate thread & stores thumbnails in xmlfile in each directory it works great, maybe with similar ithumbsProvider you could have only one QTreeView with thumbnails inside & drag&drop functionalities?
jpn (6th November 2007)
connect clicked(const QModelIndex &) or doubleClicked(const QModelIndex &) signal to slot that setRootIndex ( const QModelIndex & ) for index in first column & the same row as passed in signal...
invictus (7th November 2007)
Speaking of problems...
This is my goTo slot (much like your setRootIndex):
dirView is a QTreeView. The problem is that when the up method is run (which run goTo() with the parent() of the dirView rootIndex like in your example) the program just quits/crashes. If I comment the if(dirView->isDir()) line it works.void goTo(const QModelIndex &dir)
{
if(dirModel->isDir(dir))
{
dirView->setRootIndex(dir);
addressField->setText(dirModel->filePath(dir));
upAction->setEnabled(dir.isValid());
}
}
Last edited by invictus; 7th November 2007 at 22:10.
hello.// how an i load the files from the file list so that i an get its directory to load the file itself to transfer it to another device..thanks!
Hi I'm doing that thing with the contents of clipboard.. ( a simple enumeration )
const QMimeData *mime = QApplication::clipboard()->mimeData();
if (mime && mime->hasUrls()) {
QStringList fileList;
foreach(QUrl url, mime->urls())
fileList.append(url.toLocalFile());
........
But If clipboard was filled by a windows application I can't know if I I need to copy or cut ..... do you know a trick ????
Bookmarks