How to add columns in QTableView?
-
wrote on 3 Jan 2021, 04:52 last edited by _jao_victor_ 1 Mar 2021, 04:52
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?
wrote on 4 Jan 2021, 08:01 last edited by JonB 1 Apr 2021, 08:02@_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.
wrote on 3 Jan 2021, 07:58 last edited by@_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.
wrote on 3 Jan 2021, 18:38 last edited by@SGaist When you say model, do you mean a database table?
-
No, a model is not limited to a database.
See here.
-
@SGaist When you say model, do you mean a database table?
wrote on 4 Jan 2021, 08:01 last edited by JonB 1 Apr 2021, 08:02@_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. -
wrote on 6 Jan 2021, 04:20 last edited by
@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?
1/7