【发布时间】:2016-05-09 22:27:14
【问题描述】:
当单击按钮时,我需要一些帮助来同时从某些列表中删除某些项目。
这是代码:
class Window(QMainWindow):
list_1 = [] #The items are strings
list_2 = [] #The items are strings
def __init__(self):
#A lot of stuff in here
def fillLists(self):
#I fill the lists list_1 and list_2 with this method
def callAnotherClass(self):
self.AnotherClass().exec_() #I do this to open a QDialog in a new window
class AnotherClass(QDialog):
def __init__(self):
QDialog.__init__(self)
self.listWidget = QListWidget()
def fillListWidget(self):
#I fill self.listWidget in here
def deleteItems(self):
item_index = self.listWidget.currentRow()
item_selected = self.listWidget.currentItem().text()
for i in Window.list_2:
if i == item_selected:
?????????? #Here is where i get confussed
当我使用组合键打开QDialog 时,我在QListWidget 中看到了一些项目。在deleteItems 方法中,我从QListWidget 中选择的项目中获取索引和文本。效果很好。
当我按下一个按钮(我已经创建)时,我需要做的是从list_1、list_2 和QListWidget 中删除该项目。
我该怎么做?希望你能帮助我。
【问题讨论】:
标签: python list pyqt qlistwidget