问题描述
我有 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())