选择多个项目时如何清除QListView的选择? [英] How to clear the selection of QListView when multiple items are selected?

查看:897
本文介绍了选择多个项目时如何清除QListView的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Qt App,其中有一个QListView.列表中没有几个项目.我的应用程序要求根据用户的选择重新排列项目.一切正常,但我面临一个小问题.

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.

当我使用鼠标进行多项选择时,即通过拖动鼠标来选择项目,即使我进行了一些重新排列操作后,它也会在QlistView上留下选择标记.我确信它与清除选择有关.我尝试使用repaint()或clearFocus(),但似乎没有任何效果.

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.

例如,当我们选择一组文件夹时,我们拖动鼠标,该实习生会给我们一个矩形框,该矩形框覆盖了它下面的所有项目.那个特定的矩形框留在我的QListView中.选择项目后,我不想要它.

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.

我正在执行一个mousemoveevent:

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();
    } 

如果您注意到QT_NO_DEBUG区域,您将看到我的清除焦点和重新粉刷,但是没有任何帮助.可以解决这个问题吗?

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 .:我正在发布模式下运行它.

P.S.: I am running it in a release mode.

推荐答案

使用

void QAbstractItemView::clearSelection() [slot]

清除选择

此外,所有视图都有一个选择模型,您可以通过以下模型进行访问:

Also, all views have a selection model you can access through:

QItemSelectionModel * QAbstractItemView::selectionModel() const

允许选择更多内容

查看另一件事...

#ifdef QT_NO_DEBUG

意味着释放

#ifndef QT_NO_DEBUG

将是调试模式,并且确定不会编译您粘贴的代码

would be debug mode, and im sure, it will not compile the code you pasted

这篇关于选择多个项目时如何清除QListView的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆