Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. about use QAbstractItemModel and directly use QTreeWidget/QListWidget
Forum Updated to NodeBB v4.3 + New Features

about use QAbstractItemModel and directly use QTreeWidget/QListWidget

Scheduled Pinned Locked Moved General and Desktop
11 Posts 4 Posters 2.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by mcosta
      #2

      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

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • O Offline
        O Offline
        opengpu2
        wrote on last edited by
        #3

        yep, is there any open source demo of FileBrowser?

        1 Reply Last reply
        0
        • O Offline
          O Offline
          opengpu2
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • O Offline
            O Offline
            opengpu2
            wrote on last edited by
            #5

            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?

            1 Reply Last reply
            0
            • O Offline
              O Offline
              opengpu2
              wrote on last edited by
              #6

              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?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mcosta
                wrote on last edited by
                #7

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

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  opengpu2
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0
                  • O Offline
                    O Offline
                    opengpu2
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      So QSqlTableModel ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        Vince Golubic
                        wrote on last edited by
                        #11

                        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->setSelectionMode(QAbstractItemView::SingleSelection);
                        			ui->treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
                        			ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
                        		    ui->treeView->setIndentation(12);
                        			ui->treeView->header()->setHighlightSections(true);
                        			ui->treeView->header()->setProperty("showSortIndicator", QVariant(false))
                        		    ui->treeView->expandAll();
                        		    ui->treeView->show();
                        			model = new TreeModel (mainObj*, this );
                                    ui->treeView->setDragDropMode(QAbstractItemView::InternalMove);
                        
                        Hope that helps - Vince
                        
                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved