0

SelectItems 動作で QTableView を ExtendedSelection モードで使用します。
次の動作を実装したいと思います:
1) 1 つのセルのみが選択されている場合 - 何もしない
2) 複数のセルが選択されている場合 - 選択したセルごとに行全体を選択します。

次に例を示します。

void BaseTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{   
    QTableView::selectionChanged(selected, deselected);
    QItemSelection currentSelection = selectionModel()->selection();

    //table has selection 
    if(!currentSelection.isEmpty())
    {
        QItemSelectionRange selectionRange = currentSelection.first();

        //select whole row if more than one cell is selected
        if(currentSelection.count() > 1 || selectionRange.height() > 1 || selectionRange.width() > 1)
        {
            if(!deselected.isEmpty())
                selectionModel()->select(deselected, QItemSelectionModel::Deselect | QItemSelectionModel::Rows);
            if(!selected.isEmpty())
                selectionModel()->select(currentSelection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
        }
    }
}  

このコードは何とか機能します。しかし、私はより良い解決策を見つけることができません。
問題点:
1) マウス使用時の選択項目の点滅。おそらく、 の二重呼び出しselectionChangedか、このようなことが原因です。
2) Shift キーによる選択が正しく動作しません。Shift キーを押した状態で選択領域を変更するdeselectedと、常に空になります。したがって、選択は常に増加します。

記述された動作を実装するためのより良い解決策は何ですか?
押されたキーで選択を修正するにはShift?

4

1 に答える 1

0

別の解決策を見つけました。

select()のメソッドを再実装しQItemSelectionModelました。いくつかのチェックを行いRows、初期フラグにフラグを追加するだけで十分です。

于 2013-09-24T17:28:22.533 に答える