Here I have defined a simple abstract list model
from PySide6 import QtCore
from PySide6.QtUiTools import QUiLoader
from PySide6.QtWidgets import QApplication, QMainWindow
from PySide6.QtCore import QAbstractListModel, Qt
loader = QUiLoader()
class TodoModel(QAbstractListModel):
def __init__(self, todos=None):
super().__init__()
self.todos = todos or []
def data(self, index, role):
if role == Qt.DisplayRole:
status, text = self.todos[index.row()]
return text
def rowCount(self, index):
return len(self.todos)
This is where I load the application.
class MainWindow(QtCore.QObject):
def __init__(self):
super().__init__()
self.wid = loader.load("todo.ui", None)
self.model = TodoModel(todos=[(False,"hello world")])
self.wid.linedit.setModel()
self.wid.show()
app = QApplication([])
ui = MainWindow()
app.exec()
I am getting the error the attribute is not present. I understand; I am inheriting a QObject that does not have that attribute; I Tried inheriting the QMainWIndow and the TodoModel.
All of them are giving me some or the other kind of error.
Ideally, I want to display in the todo widget in the lineEdit
(QLineEdit)
the value "hello world".
What needs to change. Also, I cannot use the pyside6-uic
.UI file has to be loaded using the QuiLoader
Adding Traceback
qt.pysideplugin: Environment variable PYSIDE_DESIGNER_PLUGINS is not set, bailing out.
qt.pysideplugin: No instance of QPyDesignerCustomWidgetCollection was found.
Traceback (most recent call last):
File "/home/danish/playground/QT/Second_TUT/ui_test/main.py", line 35, in <module>
ui = MainWindow()
File "/home/danish/playground/QT/Second_TUT/ui_test/main.py", line 30, in __init__
self.wid.lineEdit.setModel()
AttributeError: 'PySide6.QtWidgets.QLineEdit' object has no attribute 'setModel'
Process finished with exit code 1
How to add this list model to the QLineEdit to display inside the QLineEdit "hello world" ?