2016-08-19 20 views
1

tableViewにフィルタリングとソート方法を追加しようとしています。そのためには、QSortFilterProxyModelを使用する必要があります。私の問題は、魔法使いの最初のモデルでは、QSortFilterProxyModelを使用すると、テーブルのすべてのセルがエディタのmodですでに開いている必要があるということです。 QStandardItemModelQSortFilterProxyModelに追加した後、セルは編集可能モードにはまだありません。openPersistentEditorのQSortFilterProxyModel

これは期待通りに働いている:

QStandardItemModel *model = new QStandardItemModel(0, 5, this); //reimplemented class 
QItemDelegate *mydelegate = new QItemDelegate(this); //reimplemented class 

ui -> tableView -> setModel(model); 
ui -> tableView -> setItemDelegate (mydelegate); 

for(size_t i=0; i<m_BoardingsVector.size(); i++) //a structure from a function that adds rows dynamically 
{ 
     model -> insertRows(model -> rowCount(),1); 
     for(int j=0; j<5; ++j) 
     ui -> tableView -> openPersistentEditor(model -> index(model -> rowCount() - 1, j)); 
} 

細胞は、私はセルをダブルクリックした場合にのみ表示されます。つまり、tableViewopenPersistestentEditorメソッドが正しく機能していないことを意味します。

QStandardItemModel *model = new QStandardItemModel(0, 5, this); //reimplemented class 
QItemDelegate *mydelegate = new QItemDelegate(this); //reimplemented class 

QSortFilterProxyModel * m_proxyModel = new QSortFilterProxyModel(); 
m_proxyModel -> setSourceModel(model); 

ui -> tableView -> setModel(m_proxyModel); 
ui -> tableView -> setItemDelegate (mydelegate); 
ui -> tableView -> sortByColumn(0, Qt::AscendingOrder); 
ui -> tableView -> setSortingEnabled(true); 


for(size_t i=0; i<m_BoardingsVector.size(); i++) //a structure from a function that adds rows dynamically 
{ 
     model -> insertRows(model -> rowCount(),1); 
     for(int j=0; j<5; ++j) 
     ui -> tableView -> openPersistentEditor(model -> index(model -> rowCount() - 1, j)); 
} 

答えて

0

私はこの問題を持っていたし、ちょうどあなたの質問やコードの抜粋を読んだことは私がミスを実感しました:

ビュー(ui->tableView)は一つのモデル(m_proxyModel)で動作するように設定されているが、インデックスのためにエディタは別のモデル(model)から来ています。これはおそらく、この見解には意味を持たないでしょう。

変更:

ui -> tableView -> openPersistentEditor(model -> index(model -> rowCount() - 1, j)); 

に:

ui -> tableView -> openPersistentEditor(m_proxyModel -> index(model -> rowCount() - 1, j)); 

はあなたの問題の世話をする必要があり、私は信じています。

エディタが正しいセルに表示されないという別の問題が発生しましたが、サブクラスの実装にはQAbstractProxyModel(通常はお勧めできません)という問題が考えられます。


私はQAbstractItemViewためsource codeで短い一見を取って、私はまだ明示的な制限を見つけられませんでしたが、それはまだ私は考えることができる最も合理的な説明です。

関連する問題