I am working on a Qt App where I have a QListView. There are few items present in the list. My application requires items to be rearranged according to user's choice. Everything is working fine but I am facing a small issue.
When I do multiple selection using a mouse i.e. select items by dragging the mouse, it leaves the selection mark on the QlistView even after I do some rearranging operation. I am sure its got something to do with clearing the selection. I tried to use repaint() or clearFocus() but nothing seems to be working.
E.g When we select a group of folders we drag our mouse, which intern gives us rectangular box which covers all the items which come under it. That particular rectangle box stays inside my QListView. I do not want it after I have selected the items.
I have a mousemoveevent inside which I am doing it:
void BinListView::mouseMoveEvent (QMouseEvent *event) {
if (NULL == event) {
return;
} else {
if (Qt::LeftButton & event->buttons ()) {
int nDis = (event->pos () - m_posStart).manhattanLength ();
if (nDis >= QApplication::startDragDistance ()) {
startDrag (m_posStart);
}
}
#ifdef QT_NO_DEBUG
QListView::mouseMoveEvent (event);
QListView::repaint();
QListView::clearFocus();
#endif
}
repaint();
}
If you notice QT_NO_DEBUG area, you will see my clearing focus and repainting but nothing is helping me. ANy solution to this problem?
P.S.: I am running it in a release mode.
Use the QAbstractItemView::clearSelection function.
If you have subclassed
QListView
you can just call it withclearSelection();
Use
to clear selection
Also, all views have a selection model you can access through:
that allows doing a lot more things selecting
Look at Handling selections in item views
Another thing ...
means release
would be debug mode, and im sure, it will not compile the code you pasted