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 get source QAbstractTableModel from QSortFilterProxyModel
Qt 6.11 is out! See what's new in the release blog

How to get source QAbstractTableModel from QSortFilterProxyModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 801 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    class myModel : public QAbstractTableModel
    {
    Q_OBJECT
    public:
    myModel();
    private:
    string lists;
    }

    class myProxyModel: public:QSortFilterProxyModel {
    public:
    virtual QVariant headerData(int column ,Qt::Orientation orientation, int role) const;
    };

    class myWIndow: QWidget {
    createWindow();

    private:
    myProxyModel windowProxyModel;
    myModel
    windowModel;

    }

    void myWindow:createWindow() {
    QTableView* view = new QTableView();
    windowModel = new myModel();
    windowProxyModel = new myProxyModel();
    windowProxyModel ->setSourceModel(windowModel );
    view->setModel(windowProxyModel);

    }

    /* since we want the *to display headers in the tableview */
    QVariant windowProxyModel ::headerData(int section ,Qt::Orientation orientation, int role) const
    {
    if (role == Qt::DisplayRole && (orientation == Qt::Horizontal) ) {
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    I want to access myModel ->lst varaible (string)

    }

    if (role == Qt::DisplayRole && (orientation == Qt::Vertical)) {
    return section;
    }
    return QVariant();
    }

    Could someone how to guide how access member of source (QAbstractTableModel) from ProxMode ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @Qt-Enthusiast said:
      You can get the models' model with
      http://doc.qt.io/qt-5/qabstractproxymodel.html#sourceModel

      To get a myModel from it. you will need to qobject_cast it
      then you can access Public variables.

      1 Reply Last reply
      2

      • Login

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