Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-26856

MAC - filterAcceptsRow with custom modelview used for QFileDialog does not work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 4.7.4
    • None
    • MAC 64 bit Lion 10.7
    • macOS

    Description

      #include "myclass.h"
      #include <QDir>
      #include <QString>
      #include <Qdebug>
      #include <QFileSystemModel>
      myclass::myclass(QObject *parent)
      : QSortFilterProxyModel(parent)
      {
      }

      bool myclass::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
      {

      QModelIndex index = sourceModel()->index(source_row, 0/column/, source_parent);
      QFileSystemModel* filemodel = qobject_cast<QFileSystemModel*>(sourceModel());
      QFileInfo indexInfo = filemodel->fileInfo(index);
      //qDebug () << files << files.contains("Setting.dB");

      if (indexInfo.fileName()==QString("Setting.dB"))

      { return true; }

      else return false;

      /*
      if( indexInfo.isDir())
      return true;
      else if (indexInfo.isFile() && indexInfo.fileName() == QString("Setting.dB"))
      return true;
      else return false;
      */

      }

      In another class

      void Login::on_loginbrowse_clicked()
      {
      // selecting a new setting.dB file
      //QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(parent);
      //filterModel->setSourceModel(stringListModel);

      QFileDialog *fileDialog = new QFileDialog;
      //you implemented MyClass as proxy model so you need to set it in QFileDialog as proxyModel
      myclass *proxyModel = new myclass;
      fileDialog->setProxyModel(proxyModel);
      fileDialog->show();

      }

      Result

      Window showing all files and not the required one which is wrong

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            sherifomran Sherif Omran
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes