How to print more than one items in QListWidget if more than one items selected(如果选择了多个项目,如何在 QListWidget 中打印多个项目)
本文介绍了如果选择了多个项目,如何在 QListWidget 中打印多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 QListWidget 并且那里有字符串,当我选择一个字符串时,我想显示它的索引号和文本.但问题是,如果我选择超过 1 个项目,它不会显示所有索引.它只显示一个.
I have QListWidget and there are strings there, when I select a string, I wanted to display the index number and text of that. But the problem is, if I select more than 1 items, it doesn't display all of the indexes. It displays only one.
from PyQt5.QtWidgets import *
import sys
class Pencere(QWidget):
def __init__(self):
super().__init__()
self.layout = QVBoxLayout(self)
self.listwidget = QListWidget(self)
self.listwidget.addItems(["Python","Ruby","Go","Perl"])
self.listwidget.setSelectionMode(QAbstractItemView.MultiSelection)
self.buton = QPushButton(self)
self.buton.setText("Ok")
self.buton.clicked.connect(self.but)
self.layout.addWidget(self.listwidget)
self.layout.addWidget(self.buton)
def but(self):
print (self.listwidget.currentRow()+1)
uygulama = QApplication(sys.argv)
pencere = Pencere()
pencere.show()
uygulama.exec_()
如果我选择超过 1 个项目,如何显示所有项目名称和索引?
How can I display all of the items names and indexes if I select more than 1 items?
推荐答案
我用这个解决了
def but(self):
x = self.listwidget.selectedItems()
for y in x:
print (y.text())
这篇关于如果选择了多个项目,如何在 QListWidget 中打印多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如果选择了多个项目,如何在 QListWidget 中打印多个项目


基础教程推荐
猜你喜欢
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01