开发者

Browse, List and Delete files with qt

开发者 https://www.devze.com 2023-01-26 08:33 出处:网络
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.

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.

Browse, List and Delete files with qt

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 */
voi开发者_C百科d 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消