马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 klikli234 于 2024-4-18 21:07 编辑
不知道怎么回事. 我检查了对象好像也没有被销毁就莫名奇妙崩溃了, 看代码# This Python file uses the following encoding: utf-8
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QMainWindow, QListWidgetItem
# Important:
# You need to run the following command to generate the ui_form.py file
# pyside6-uic form.ui -o ui_form.py, or
# pyside2-uic form.ui -o ui_form.py
from ui_form import Ui_MainWindow
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
item1 = QListWidgetItem("task 1")
item2 = QListWidgetItem("task 2")
self.ui.listWidget.addItem(item1)
self.ui.listWidget.addItem(item2)
action_data_list: List[QListWidgetItem] = []
action_data_list_2: List[QListWidgetItem] = []
action_data_list.append(QListWidgetItem("action 1"))
action_data_list.append(QListWidgetItem("action 2"))
self.ui.listWidget_2.addItem(action_data_list[0])
self.ui.listWidget_2.addItem(action_data_list[1])
item1.setData(Qt.UserRole, action_data_list)
item2.setData(Qt.UserRole, action_data_list_2)
self.ui.listWidget.itemClicked.connect(self.reload)
# reload item to listWidget_2
def reload(self):
current_item = self.ui.listWidget.currentItem()
action_data_list = current_item.data(Qt.UserRole)
for i in range(self.ui.listWidget_2.count()):
self.ui.listWidget_2.takeItem(0)
self.ui.listWidget_2.clear()
for action_data in action_data_list:
self.ui.listWidget_2.addItem(action_data)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = MainWindow()
widget.show()
sys.exit(app.exec())
调用reload 函数就会导致这个问题.请帮我看看,非常感谢. |