Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Creating a sort of file explorer layout in Qt



  • I did some research to find the best widget for creating a sort of table. I concluded that a table widget would be best but after using it a bit, it appears that's not going to work.

    I essentially want to create this:
    alt text
    Each entry will be a row, and they can be sorted by Name, Date, Type, etc...
    So far, a Table is not working because I don't want to select everything in a grid. It should stay as a row.
    Is something like this readily available as a Qt widget, or will I have to create a custom widget?



  • @johnratius
    Well, that example does use Qt's QFileSystemModel. You will want to replace that with your own model, so there will be some changes. But the item view UI is the right principle.

    EDIT One thing: You said

    I concluded that a table widget would be best but after using it a bit, it appears that's not going to work.

    Actually as a beginner I might have recommended you to a QTableWidget, why did you reject it? It is just a ready-rolled QTableView with a simple, internal database attached. I don't think you have any special requirements? Ah --- are you going to use a proper database for your books? Then it would not be best. But QSqlTableModel + QTableView can be used.


  • Qt Champions 2019



  • @Christian-Ehrlicher This will work with items other than folders and files? I am creating a database of books with info so it will read book titles and authors.

    Edit: https://doc.qt.io/archives/qt-5.10/modelview.html
    From what I can tell, it is a QTableView I need, but I am unsure how to set it up properly.



  • @johnratius
    Well, that example does use Qt's QFileSystemModel. You will want to replace that with your own model, so there will be some changes. But the item view UI is the right principle.

    EDIT One thing: You said

    I concluded that a table widget would be best but after using it a bit, it appears that's not going to work.

    Actually as a beginner I might have recommended you to a QTableWidget, why did you reject it? It is just a ready-rolled QTableView with a simple, internal database attached. I don't think you have any special requirements? Ah --- are you going to use a proper database for your books? Then it would not be best. But QSqlTableModel + QTableView can be used.



  • @JonB Ah did not know about SQTable. I will take a look into that, thanks!



  • @johnratius
    If you are going to use a SQL database (can even be file-based SQLite), then see https://doc.qt.io/qt-5/sql-presenting.html and the example at https://doc.qt.io/qt-5/qtsql-tablemodel-example.html, for QSqlTableModel + QTableView You can ignore the "editing" stuff if you just want to display the books table. In the first link they mention how you can disable editing on the table view, and then don't worry about the editing/modifying methods.



  • @JonB Thanks! In the future I will add some sort of editing feature, but for now it will just be viewing.


Log in to reply