QListWidget 和多选 [英] QListWidget and Multiple Selection

查看:89
本文介绍了QListWidget 和多选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个常规的 QListWidget 连接了几个信号和插槽.一切都按我的预期工作.我可以更新、检索、清除等

I have a regular QListWidget with couple of signals and slots hookedup. Everything works as I expect. I can update, retrieve, clear etc.

但用户界面不支持多选.

But the UI wont support multiple selections.

如何启用"QListWidget 的多项选择?我对 PyQt 的有限经验告诉我,我需要通过子类化来创建一个自定义的 QListWidget ......但是接下来怎么办?

How do I 'enable' multiple selections for QListWidget? My limited experience with PyQt tells me I need to create a custom QListWidget by subclassing .. but what next?

Google 给了我 C++ 答案,但我正在寻找 Python

Google gave me C++ answers but I'm looking for Python

http://www.qtforum.org/article/26320/qlistwidget-multiple-selection.html

http://www.qtcentre.org/threads/11721-QListWidget-多选

推荐答案

很遗憾,我对 Python 特定的语法无能为力,但您不需要创建任何子类.

Unfortunately I can't help with the Python specific syntax but you don't need to create any subclasses.

在您的 QListWidget 创建后,使用传入的多个选择类型之一调用 setSelectionMode(),可能 QAbstractItemView::ExtendedSelection 是你想要的那个.您可能需要查看此模式的一些变体.

After your QListWidget is created, call setSelectionMode() with one of the multiple selection types passed in, probably QAbstractItemView::ExtendedSelection is the one you want. There are a few variations on this mode that you may want to look at.

itemSelectionChanged() 信号的插槽中,调用 selectedItems() 以获取 QListWidgetItemQList> 指针.

In your slot for the itemSelectionChanged() signal, call selectedItems() to get a QList of QListWidgetItem pointers.

这篇关于QListWidget 和多选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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