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 limit number shown rows in list model using proxy model?
Forum Updated to NodeBB v4.3 + New Features

How to limit number shown rows in list model using proxy model?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 689 Views 2 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
    Subuday
    wrote on last edited by
    #1

    I can't figure out how to limit number shown rows in list model using proxy model?

        filterModel->setSourceModel(&langListModel);
        filterModel->setFilterRole(langListModel.NameRole);
    
    #include "langlistmodel.h"
    
    LangListModel::LangListModel(QObject *parent):
        QAbstractListModel(parent)
    {
    
    }
    
    
    int LangListModel::rowCount(const QModelIndex &parent) const
    {
        if (parent.isValid()) {
            return 0;
        }
    
        return listData.size();
    }
    
    QVariant LangListModel::data(const QModelIndex &index, int role) const
    {
        if (!index.isValid()) {
            return QVariant();
        }
    
        switch (role) {
        case IDRole:
            return listData.at(index.row()).value("id");
        case NameRole:
            return listData.at(index.row()).value("name");
        default:
            return QVariant();
        }
    }
    
    QHash<int, QByteArray> LangListModel::roleNames() const
    {
        QHash<int, QByteArray> roles = QAbstractListModel::roleNames();
        roles[NameRole] = "name";
        roles[IDRole] = "IDLang";
    
        return roles;
    }
    
    void LangListModel::add(const QMap<QString, QString> &unit)
    {
        beginInsertRows(QModelIndex(), listData.size(), listData.size());
        listData.append(unit);
        endInsertRows();
    }
    
    int LangListModel::size() const
    {
        return listData.size();
    }
    
    void LangListModel::clear()
    {
        beginRemoveRows(QModelIndex(), 0, listData.size());
        endRemoveRows();
        listData.clear();
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What do you have for
      setFilterRegExp( );
      https://doc.qt.io/qt-5/qsortfilterproxymodel.html#filterRegExp-prop
      or https://doc.qt.io/qt-5/qsortfilterproxymodel.html#setFilterFixedString
      to do the actual filtering ?

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

        Hi,

        To add to @mrjj : https://doc.qt.io/qt-5/qsortfilterproxymodel.html#filterRegularExpression-prop ?

        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
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Isn't that the same question as you posted here ?

          Thus the same answer as @JonB applies here too:

          @Subuday said in How to limit number shown rows in list model using proxy model?:

          int LangListModel::rowCount(const QModelIndex &parent) const
          {
          if (parent.isValid()) {
          return 0;
          }

          return listData.size();
          

          }

          You got your if wrong.

          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
          2

          • Login

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