QtSql Dataaware cells/boxes
-
I find the examples very helpful from Qt regarding Sql possibilities given by Qt. Thanks on this place.
Here is one of this examples:
When I click inside a box of the row "Genre" or "Author Name" than a dropdown appears like you can see on the picture, - highlighted with red frame.
BUT
This functionality is only given because it is used QSqlRelationalTableModel and with the function "setRelation" a relation is set to this columns "Genre" and "Author Name".MY QUESTION
Is there a comfortable possibility given to do the same stuff only without QSqlRelationalTableModel?
Means there is a table like this
Only such table without any relations to other tables. And it should not be the aim to create related tables.Now when I decide to change from ProcessMGA the Atribute "HasToDoWith" I would like to get the dropdown list where I can EITHER select from already existing values inside the attribute "HasToDoWith" OR just write a new one like "Banana".
-
I found newly this possibility
ui->QComboBox1->setModel(QSqlTblModel);
But well that is a ComboBox and not something inside the TableView.
But here I also need to find out how to say which attribute of the QSqlTblModel shall be taken inside the dropdown list of the combobox. -
- need to find out how to say which attribute of the QSqlTblModel shall be taken inside the dropdown
Hi
Sounds to me you are looking for
http://doc.qt.io/qt-5/qcombobox.html#modelColumn-prop
(to select what column that is used in combobox) -
My code looks like this
TblModel = new QSqlTableModel(this); TblModel->setTable("Tbl1"); TblModel->select(); ui->QComboBox1->setModelColumn(TblModel->fieldIndex("Attribute1"));
So the result is, although Attribute1 is filled with data, that the data will not appear in the dropdown of QComboBox.
No errors no warnings when compiling. -
Hey I got it !!! I am gutting better :) unbelivable I solved it this way:
ui->CB_AdaNr->setModel(TblModel); ui->CB_AdaNr->setModelColumn(TblModel->fieldIndex("Attribute1"));
And it works.
Still have the issue that I would like to have dropdowns inside of the QTableView, - the topic at the top.