[英]QListWidget how to get the signal emitted?
with open('championships.txt', 'r') as rf:
lines = rf.readlines()
for line in lines:
champioshiplist.addItem(QListWidgetItem(line.strip()))
champioshiplist.doubleClicked.connect(self.listclisc)
def listclisc(self):
print('OK')
I populated the Qwidgetlist from a txt file, but I am not able to get the clicked value from the list, in the example the printing works but how can i get text of the list?我从 txt 文件中填充了 Qwidgetlist,但我无法从列表中获取单击的值,在示例中打印工作但我如何获取列表的文本? I am not able to save the clicked item.
我无法保存单击的项目。 i would like to do
我想要做
def listclisc(self):
text = championshiplist.... value
but the function doesn't see the Qwidgetlist.但 function 没有看到 Qwidgetlist。 I am new in Python and do not really understand how to do
我是 Python 的新手,不太明白该怎么做
The doubleClicked signal sends the associated QModelIndex that has the information you require: doubleClicked 信号发送具有您需要的信息的关联 QModelIndex:
def listclisc(self, index):
print('OK', index.data())
Similarly you can use the itemDoubleClicked signal:同样,您可以使用 itemDoubleClicked 信号:
champioshiplist.itemDoubleClicked.connect(self.listclisc)
def listclisc(self, item):
print('OK', item.text())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.