How to clear the selection of QListView when multiple items are selected?



  • 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.

    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.


  • Moderators

    I don't really understand you, but maybe what you are looking for is "clearSelection()":https://qt-project.org/doc/qt-4.8/qabstractitemview.html#clearSelection



  • Clear selection will not let me select the items. My concern is when I am dragging the mouse and selecting set to items, it leaves the selection mark on the list view. Am i clear now?
    [quote author="sierdzio" date="1372325608"]I don't really understand you, but maybe what you are looking for is "clearSelection()":https://qt-project.org/doc/qt-4.8/qabstractitemview.html#clearSelection[/quote]


  • Moderators

    I think it's cleared, but then I don't know the solution ;)



  • Ahhh man..... I am searching for a solution though....
    [quote author="sierdzio" date="1372326096"]I think it's cleared, but then I don't know the solution ;)[/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.