Important: Please read the Qt Code of Conduct -

about use QAbstractItemModel and directly use QTreeWidget/QListWidget

  • i know use QAbstractItemModel is more elegant, and only 1 QAbstractItemModel , can be with many View(QListView/QTreeView, etc).
    but i met some problem:

    1. how can i preview the picture file if i use QAbstractItemModel method.
      when i use QTreeWidget, while i create the QTreeWidgetItem, i can setIcon.
    2. how i can show all the dir and files in QTreeView, but only selected dir and its child files in the QListView.
      when i use QTreeWidget and QListWidget, i can control this all by myself.

    thank you

  • Hi,

    If I understood correctly you're implementing a sort of FileBrowser. (More info you provide, more you'll get :) )

    For question 1 you can write your model in such way to show the file picture (writing the ::data() method in the right way

    For question 2 you could use a QSortFilterProxyModel to filter the contents to show

  • yep, is there any open source demo of FileBrowser?

  • and in ur opinion, which method should i use, the QAbstractItemModel or directly use QTreeWidget/QListWidget?
    i will preview the file in the QListWidget as picture or even more complicated things(eg, many small widget which contains dynamic OpenGL Models)
    thank you

  • and how i deal with the Drag and Drop problem while i use QAbstractItemModel.
    eg.some TreeView allow DragDrop,while others donot allowed.
    and in the Drag and Drop, i willl pass some Data to the MainWindow.
    is it able and easy to do all this work use QAbstractItemModel?

  • and i will search or filter on some View, even re-sort the files on some View.
    is it able and easy to do all this work use QAbstractItemModel?

  • Simple question, Why you don't use QFileSystemModel for that?

  • thank you,is there any examples of QSortFilterProxyModel ?
    it seems not work for me to show only files&sub-dir of a Dir in the List, while the Tree shows all the Dir

  • QFileSystemModel is not suitable for me, because i want to read data from my database

  • Lifetime Qt Champion


    So QSqlTableModel ?

  • This might help (I hope I understand your question)
    Assuming you have a ui pointer established to a QTreeView or QTreeWidget (Note: some of the following only apply to TreeView (see documentation), but I hope you see the point:

    			ui->treeView->header()->setProperty("showSortIndicator", QVariant(false))
    			model = new TreeModel (mainObj*, this );
    Hope that helps - Vince

Log in to reply