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. need help on model/view
Forum Updated to NodeBB v4.3 + New Features

need help on model/view

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 396 Views 1 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #1

    Hi,

    I'm trying to get into model/view programming and I'm stuck.

    I want a hierarchic composition of a treeview, a table and a textview/editor. Before I start to create my own model, I wanted to learn that stuff on using QFileSystemModel.

    TreeView is working and I got the columns beside the name hidden.
    With single selection I get the path of the selected directory.
    As the model for the treeview is filtered to show directories only, I thought, I could use another instance of QFileSystemModel to show the files of the selected directory.

    But here I'm stuck.
    I tried to set the root path in the selectionChanged slot, but the table does not show any difference. I only have one row for the root - no files.

    I did similar task in java+swing. There I can ask the current tree node for its children. But I didn't found any children related function in treeview or itemmodel. Only a "hasChildren" method which returns always true ...

    How can I determine the children of the selected tree node, which in this case are the files of the selected directory?

    jeremy_kJ 1 Reply Last reply
    0
    • D django.Reinhard

      Hi,

      I'm trying to get into model/view programming and I'm stuck.

      I want a hierarchic composition of a treeview, a table and a textview/editor. Before I start to create my own model, I wanted to learn that stuff on using QFileSystemModel.

      TreeView is working and I got the columns beside the name hidden.
      With single selection I get the path of the selected directory.
      As the model for the treeview is filtered to show directories only, I thought, I could use another instance of QFileSystemModel to show the files of the selected directory.

      But here I'm stuck.
      I tried to set the root path in the selectionChanged slot, but the table does not show any difference. I only have one row for the root - no files.

      I did similar task in java+swing. There I can ask the current tree node for its children. But I didn't found any children related function in treeview or itemmodel. Only a "hasChildren" method which returns always true ...

      How can I determine the children of the selected tree node, which in this case are the files of the selected directory?

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      @django-Reinhard said in need help on model/view:

      Hi,

      I'm trying to get into model/view programming and I'm stuck.

      I want a hierarchic composition of a treeview, a table and a textview/editor. Before I start to create my own model, I wanted to learn that stuff on using QFileSystemModel.

      TreeView is working and I got the columns beside the name hidden.

      Are you using widgets or quick? The general idea is the same for both, but API details differ.

      With single selection I get the path of the selected directory.
      As the model for the treeview is filtered to show directories only, I thought, I could use another instance of QFileSystemModel to show the files of the selected directory.

      That's one option. Another is to throw a QSortFilterProxy in to remove file entries in the tree view.

      But here I'm stuck.
      I tried to set the root path in the selectionChanged slot, but the table does not show any difference. I only have one row for the root - no files.

      Can you share a code sample?

      I did similar task in java+swing. There I can ask the current tree node for its children. But I didn't found any children related function in treeview or itemmodel. Only a "hasChildren" method which returns always true ...

      How can I determine the children of the selected tree node, which in this case are the files of the selected directory?

      QAbstractItemModel::rowCount(), QAbstractItemModel::index(), and QAbstractItemModel::data() are the functions involved for directly accessing children, but they're probably the wrong level of abstraction for using an existing view rather than writing a new one. QAbstractItemView::setRootIndex() is used to point a view to a subtree of a model.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      1
      • D Offline
        D Offline
        django.Reinhard
        wrote on last edited by
        #3

        @jeremy_k said in need help on model/view:

        Are you using widgets or quick?

        I use widgets

        @jeremy_k said in need help on model/view:

        Another is to throw a QSortFilterProxy in to remove file entries in the tree view.

        Good point.
        But documentation of QSortFilterProxyModel is very limited :(

        First success: I used one QFileSystemModel for treeview and table - together with setRootIndex works fine.
        Drawback: changing sort order in tableview changes sort order in treeview too.
        So of cause - I need QSortFilterProxy.

        I tried to follow customsortfiltermodel sample, which works for filtering. The point I dislike: file properties are localized strings, so to check for directory or file I have to compare a localized representation of "directory" - oh lord!
        I have to write my own model!

        ... but I've no idea, how to translate a modelindex from source model to proxy model.

        Using QFileSystemModel I can retrieve a modelindex corresponding to a given path. Then setting rootindex of treeview and different rootindex of tableview works if there is no proxymodel.
        With proxymodel I get the error message, that the modelindex must be from the model used by the treeview. That makes sense, but here I'm stuck again.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          django.Reinhard
          wrote on last edited by
          #4

          @django-Reinhard said in need help on model/view:

          .. but I've no idea, how to translate a modelindex from source model to proxy model.

          Ok, I found the mapping methods in AbstractProxyModel ...

          ... but model filtering is pretty unusable. Don't know, whether its an issue of QFileSystemModel or whether it applies to all models ...

          My idea was to show only directories in treeview and only files in tableview. Actually I have one QFileSystemModel and two subclasses of QSortFilterProxyModel.

          When I code filterAcceptsRow to accept directories only, I won't get any entry in treeview. I have to accept drives together with directories, although a drive is never shown in treeview.

          Same happens with filterAcceptRow for the files model. When I code filterAcceptsRow to accept anything except directories, I won't get any entry in treeview.
          That's some kind of ridiculous.
          The root entry for the table view is a directory and the tableview shall only show the children of that entry. So why must the root entry pass the filter criteria?
          It will never be shown, so from my point of view there's no reason at all.

          Very strange in deed.

          Lets see, what happens with self coded models ...

          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