Question

I have created the following form with qt designer. I added a Add Files button that works with QDir and QFileDialog and loads files into a listWidget.

alt text

Here are my methods that fill this form with the files.

void RightDoneIt::changeDirectory()
{
/* select a directory using file dialog */
    QString path = QFileDialog::getExistingDirectory (this, tr("Directory"), directory.path());
    if ( path.isNull() == false )
    {
        directory.setPath(path);
        fillList();
    }
}


/*get list of file from given directory and the append it to listWidget */
void RightDoneIt::fillList()
{
    ui->listWidget->clear();
    ui->listWidget->addItems(directory.entryList());



}

I would like to modified my code so I can list the file location and the file size next to the file name and also to make this remove files button working.

I just want to be able to choose files using ctrl or command key(for macs) and press delete to remove these files from my list.

Do i have to use a QtreeWidget instead of listwidget ?

What are the best practices for doing that ?

any code suggestions ?

Thank you all!

Was it helpful?

Solution

If you are just listing files (no folder and subfolder structure), you don't need a QTreeWidget.

But as you are willing to show the file location and file size, I would use a QTableWidget (or QTableView).

However, I would suggest to have a look at QFileSystemModel. Depending on what you're trying to do you with your app, this class might come handy : You can use this model and display it in a view widget.

And QFileSystemModel comes with methods such as remove() and will also handle file renaming.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top