poonam
poonam

Reputation: 810

Python-Displaying Query results in QTreeView

I am working with python plugins for qgis.I am using python2.5 and pyqt4 designer.I used QTreeView on my .ui file. I wanted to display all the tables from database into QTreeView as the result of the query. The query is as follows:

 cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'")

I am using PostgresSQL as database.Database connection is done using psycopg2 tool. How to display result of above query into QTreeView in python??

Upvotes: 0

Views: 341

Answers (1)

Avaris
Avaris

Reputation: 36715

QTreeView requires a Model/View framework, so you need to provide a model to work with it. If you are set on using psycopg2, you need to build and populate your own model by sub-classing QAbstractItemModel from that query.

Alternatively, and more easily, you can use the Qt's QSql module. It supports PostgreSQL and provides ready-made models (like QSqlTableModel, QSqlRelationalTableModel or QSqlQueryModel) that you can use with QTreeView.

Upvotes: 1

Related Questions