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. How to override QAbstractItemModel::parent() in QSortFilterProxyModel?
Forum Updated to NodeBB v4.3 + New Features

How to override QAbstractItemModel::parent() in QSortFilterProxyModel?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 697 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.
  • I Offline
    I Offline
    Ilya Andreev
    wrote on last edited by
    #1

    I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?

    jsulmJ jeremy_kJ 2 Replies Last reply
    0
    • I Ilya Andreev

      I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ilya-Andreev I don't understand your use case. A QObject based object can only have ONE parent, returning arbitrary object as parent which is not actual parent will not change the parent/child relationship.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Ilya Andreev
        wrote on last edited by
        #3

        I think I need to clarify: I want to redefine the

        QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const
        

        not

        QObject *  QAbstractItemModel::parent()
        
        JonBJ 1 Reply Last reply
        0
        • I Ilya Andreev

          I think I need to clarify: I want to redefine the

          QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const
          

          not

          QObject *  QAbstractItemModel::parent()
          
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Ilya-Andreev said in How to override QAbstractItemModel::parent() in QSortFilterProxyModel?:

          QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const

          Well since that is virtual you can in principle override the override in QSortFilterProxyModel by sub-classing that. Whether it will behave as you desire/safely I do not know.

          I 1 Reply Last reply
          0
          • JonBJ JonB

            @Ilya-Andreev said in How to override QAbstractItemModel::parent() in QSortFilterProxyModel?:

            QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const

            Well since that is virtual you can in principle override the override in QSortFilterProxyModel by sub-classing that. Whether it will behave as you desire/safely I do not know.

            I Offline
            I Offline
            Ilya Andreev
            wrote on last edited by
            #5

            @JonB Unfortunately, overriding this function has no effect on the tree structure. Perhaps there is another way to redefine the parent without changing the original elements.

            1 Reply Last reply
            0
            • I Ilya Andreev

              I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?

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

              @Ilya-Andreev said in How to override QAbstractItemModel::parent() in QSortFilterProxyModel?:

              I want the QAbstractItemModel::parent() function to return different ancestors at will and the tree structure to change accordingly. To do this, I redefine parent() in QSortFilterProxyModel, but this does not give the desired effect. Is there any working way to override QAbstractItemModel::parent()?

              How is the view supposed to know that it needs to check the parent() of a particular item again?

              The intended path to implement this is via QAbstractItemModel::beginMoveRows and QAbstractItemMode::endMoveRows, or emit the signals mentioned in the first link directly. If the change is complicated enough, use QAbstractItemModel::beginResetModel and QAbstractItemModel::endResetModel.

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

              1 Reply Last reply
              2
              • I Offline
                I Offline
                Ilya Andreev
                wrote on last edited by
                #7

                Thanks for the answer, I'll try it and say what happened.

                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