How would you display the contents of a QtSql table using a QTreeWidget? There isn’t quite enough information around this particular subject…
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your first stop should be the introduction to model/view programming in the QT documentation. Although in the QT documentation, it applies equally to PyQt and I had to get my ahead around this recently and found it to be by far the best place to start. From this, your SQL table is the model and your tree is the view.
Specifically, you probably want to use one of QSqlQueryModel, QSqlTableModel or QSqlRelationalTableModel as your model class and QTreeView (and not
QTreeWidgetas in your question) as the view. There is example code in all of those links on how to use the different classes.But, it is unclear from your question how your table in SQL maps to a tree view – which makes providing any more detail impossible/accurate answer.
As an SQL table doesn’t naturally map to a tree you might have to look at using a proxy model or extending QAbstractItemModel yourself to work with the
QTreeViewas this will be specific to your business logic (and whether you are using nested sets or materialised path etc). If you are not storing a tree in the database, then QListView or QTableView might be more appropriate view objects anyway.