Skip to content
Advertisement

PyQT: Storing multidimensional data and displaying as QTableView using model/view framework

EDIT: I’ve changed my approach since asking this question – see answer below.

I’m building an application which displays data in a series of tables. I’m currently using PyQT’s item-based QTableWidget and manually updating the tables whenever data changes. I’d like to migrate to a model/view architecture using QAbstractItemModel and QTableView.

My data has 3 dimensions:

JavaScript

I’d like to store this data in a single model, and display different dimensions in different tables.

Data example:

JavaScript

In table1 I want to display records on the y-axis, and attributes on the x-axis, using the “edited” data_source:

JavaScript

In table2 I want to display a single record, with attribute on the y-axis and data_source on the x-axis:

JavaScript

How would I implement this using PyQT’s model/view framework, so that data is stored in a single model but represented differently for table1 and table2?

Advertisement

Answer

I’ve changed my approach since asking this question. The question came from a misunderstanding of Qt’s model/view architecture – I assumed that the model == datastore, whereas it looks like in most cases the model contains data access and update methods.

I found these two tutorials helpful in demonstrating this:

As per @musicamante’s comment, I’m now using two models to access data. Data is stored in a Pandas DataFrame with a MultiIndex (to account for the nested dictionary data), and the selection in table1 is used to set the which data is accessed in model2.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement