How to add columns in QTableView?
-
Is it possible to add columns to a QTableView using qtDesiger?
In QTableWidget just right-click to add columns and rows, is there something similar for QTableView?
I didn't find many tutorials with QTableView on the internet and in documentation.I want to take data from an existing database and place it in this QTableView without the user being able to edit or change the table properties.
-
@SGaist When you say model, do you mean a database table?
@_jao_victor_ said in How to add columns in QTableView?:
When you say model, do you mean a database table?
A model does not have to be a database, but it can be. A database is an example of a model. You cannot use a database or other model at design-time to populate a view's columns or rows in Qt Designer. You'd have to use a
QTableWidget
at design-time. And that means typing values/column headings into cells, not fetching them from a database.Using a
QTableView
attached to a model such as a database at runtime is no problem. -
Is it possible to add columns to a QTableView using qtDesiger?
In QTableWidget just right-click to add columns and rows, is there something similar for QTableView?
I didn't find many tutorials with QTableView on the internet and in documentation.I want to take data from an existing database and place it in this QTableView without the user being able to edit or change the table properties.
@_jao_victor_
My experience is that there is little you can do with aQTableView
in the Designer. You have to use theQTableWidget
there if you want to do design-time things.But
QTableWidget
is not the same asQTableView
. It is a wrapper around it, notably with its own, internal model structure. If you want to connect a table view to an existing database sourceQTableWidget
is not an optimal choice.Since you want "without the user being able to edit or change the table properties", just connect the
QTableView
to the database model at runtime and it will have the same columns. Yes, you do not get to see it laid out at design-time. -
Hi,
You cannot do that with Designer. QTableView requires a model so you'll have to do some coding to set it.
-
Hi,
You cannot do that with Designer. QTableView requires a model so you'll have to do some coding to set it.
@SGaist When you say model, do you mean a database table?
-
@SGaist When you say model, do you mean a database table?
@_jao_victor_ said in How to add columns in QTableView?:
When you say model, do you mean a database table?
A model does not have to be a database, but it can be. A database is an example of a model. You cannot use a database or other model at design-time to populate a view's columns or rows in Qt Designer. You'd have to use a
QTableWidget
at design-time. And that means typing values/column headings into cells, not fetching them from a database.Using a
QTableView
attached to a model such as a database at runtime is no problem. -
@JonB Is it possible to take the data from the table and store it in some Python structure, for example, a list and then put it in a QTableView?