Below is my example code:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(691, 327)
self.listWidget = QtWidgets.QListWidget(Form)
self.listWidget.setGeometry(QtCore.QRect(70, 40, 256, 192))
self.listWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
self.listWidget.setObjectName("listWidget")
self.plainTextEdit = QtWidgets.QPlainTextEdit(Form)
self.plainTextEdit.setGeometry(QtCore.QRect(360, 40, 261, 191))
self.plainTextEdit.setTabChangesFocus(True)
self.plainTextEdit.setReadOnly(True)
self.plainTextEdit.setObjectName("plainTextEdit")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
lists = ["one","two","Three"]
for i in lists:
item = QtWidgets.QListWidgetItem(i)
item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable)
item.setCheckState(QtCore.Qt.Unchecked)
self.listWidget.addItem(item)
self.listWidget.itemClicked.connect(self.on_listWidget_itemClicked)
def on_listWidget_itemClicked(self, item):
lines = self.plainTextEdit.toPlainText()
line_list = []
#if item.listWidget().itemWidget(item) != None:
if item.checkState() == QtCore.Qt.Checked:
self.plainTextEdit.appendPlainText(item.text())
elif item.checkState() == QtCore.Qt.Unchecked:
print(item.text())
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
in this example i am using QListWidget with ItemIsUserCheckable and QPlainTextEdit. I able to getting items from Qlistwidget to QPlainTextEdit using with Checkboxes. If i check the item in Qlistwidget it is able to setting the text in to QPlaintextEdit. But i want to remove or delete the same text in QplainTextEdit when i uncheck the item box. For example if i check the item in Qlistwidget "one", it is setting "one" into the QplainTextEdit and the same item should be deleted when i uncheck the item. Is it possible if it is possible How to do?
Do not modify the code generated by Qt Designer but create another class that inherits from the appropriate widget and use the initial class to fill it.
Update