PDA

View Full Version : How should I select QListWidgetItem by space-key



cookieki
6th November 2010, 18:22
QAbstractItemView.ExtendedSelection allows just ctrl, shift combination.
Is it possible only by using subclassing?

wysota
7th November 2010, 12:10
Use MultiSelection.

cookieki
7th November 2010, 15:21
Thanks, wysota.
But MultiSelection allows ONLY space-key.
I want the selection of using 'shift + direction key' and 'space-key'.
After all, subclassing is the solution, right?:(

wysota
7th November 2010, 16:40
Yes, you can always subclass.

cookieki
8th November 2010, 10:32
I tried to do subclassing of QAbstractItemViewPrivate::multiSelectionCommand.
But that is not virtual:(
Should I copy&paste all of the code of QAbstractItemViewPrivate to change only 'multiSelectionCommand'?

wysota
8th November 2010, 11:44
In my opinion you only need to reimplement keyPressEvent.

cookieki
8th November 2010, 12:21
In my opinion you only need to reimplement keyPressEvent.

I have no idea.


void QAbstractItemView::keyPressEvent(QKeyEvent *event)
{
..
QItemSelectionModel::SelectionFlags command = selectionCommand(newCurrent, event);
...
}


Did you mean that change 'selectionCommand' to another?
I need detail.

wysota
8th November 2010, 12:38
No, I meant to manipulate the item selection model of the view.

A simplified version would be something close to this:

void MyView::keyPressEvent(QKeyEvent *event){
if(event->key()!=Qt::Key_Space) { QAbstractItemView::keyPressEvent(event); return; }
selectionModel()->select(currentIndex(), QItemSelectionModel::SelectCurrent);
}

cookieki
8th November 2010, 18:08
No, I meant to manipulate the item selection model of the view.

A simplified version would be something close to this:

void MyView::keyPressEvent(QKeyEvent *event){
if(event->key()!=Qt::Key_Space) { QAbstractItemView::keyPressEvent(event); return; }
selectionModel()->select(currentIndex(), QItemSelectionModel::SelectCurrent);
}

Thanks, wysota.
It's not so simple.
I want exactly 'Total Commander' style.
To push direction key,with no shift key, is unselect all on ExtendedSelection mode.
TC is not that. It's keep the selection state.

I thought an idea. change between ExtendedSelection and MultiSelection.
Basically set the MultiSelection and then change to the ExtendedSelection when shift and direction is pushed.
But it's not works correctly. selection set is borken. I think maybe each mode have each selection set.

The way you suggested has unselect-all-problem, too.
Is there better way?

wysota
9th November 2010, 10:18
The way you suggested has unselect-all-problem, too.
Is there better way?
It's just an idea you can build upon, not a ready solution. You can implement with it any selection algorithm you want.