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. QTreeView QFileSystemModel .. edit item displayed name
Forum Updated to NodeBB v4.3 + New Features

QTreeView QFileSystemModel .. edit item displayed name

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.9k 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.
  • S Offline
    S Offline
    sapym
    wrote on last edited by
    #1

    Hello,

    I'm a little bit lost regarding QTreeView, QFileSystemModel, QSortFilterProxyModel and QModelIndex on Qt 5.1.0

    I want to do a custom file browser on my app..

    The folder to be displayed should respect a certain hierarchy... I manage to do that by using QSortFilterProxyModel and reimplementing filterAcceptsRow ...prefect...

    But know... I want to change the way filenames are displayed.... example : "AA1234_1.txt" and its brother item "AA1234_2.txt" should be displayed by just one item "AA1234" in the file browser

    Do you think it's possible ?

    I tried sourceModel()->setData(index0,QVariant("AA1234"),Qt::DisplayRole); in my function filterAcceptsRow

    but it's rejected...

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      instead of setting the data you should return true for the first file and for the second (all other files which you want to bundle together) return false. So they get hidden.
      Then overload the data() method and filter out the part which you want to strip out of the file name.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sapym
        wrote on last edited by
        #3

        Thanks for your answer.

        Yes indeed, I managed to hide the others files... but can't manage to change the display name

        ... how should I do to overload data() ?
        Isn't it the method supposed to give the name...
        How do I retrieve the name coming in ? (am I clear ?)

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          call the base class implementation and edit it's return value. Return the edited value...

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sapym
            wrote on last edited by
            #5

            All Right !!! I got it ! Not perhaps the sexiest way of doing it but anyway, thanks for your time answering me, it made me think a little further !
            @
            QVariant MyItemModel::data(const QModelIndex &index, int role) const
            {
            if (!index.isValid())
            return QVariant();

            QVariant initial_value;
            initial_value = QFileSystemModel::data(index,role);

            if (role == Qt::DisplayRole)
            {
            QString czName = initial_value.toString();

            if (czName.right(4).compare(".txt") == 0)
            {
            czName.chop(czName.length()-czName.lastIndexOf("_"));
            initial_value.setValue(czName);
            }
            }

            return initial_value;
            }
            @

            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