Qt6 - show in ComboBox specified column
-
Hi,
i have a Problem to show a specified Column from a Model in a ComboBox.Base-Information:
- Qt6.7
- override QSqlRelationalTableModel with multiple columns defined as "display"-Role
- QtQuick
--> TableView to show all data with role "display"
--> ComboBox to select. The column 2 of the Model have to be shown
In the documentation of the ComboBox is written, that the "textRole" is used to show the right data of multiple column-Model. Now my Model needs to be defined the role-name as "display" (or any other) to use one delegate in my TableView. But when i want to show the specified column in the ComboBox, there donest work with the same model, while the role-name are only "display". The ComboBoy show only the first column.
What can i do, that the TableView show all data with one delegate and the ComboBox lists the right, second column of my model.
Thanks for help.
-
i got it! The Solution was so simple.
For the reimplementation of the QSqlRelationalTableModel i have to define the roleNames. But i doesn't misunderstood the roleTypes.The RoleTypes are pre-defined by Qt like Qt::UserRole or Qt::DisplayRole.
To define roles by my self i can use the values over Qt::UserRole (like Qt::UserRole + i). I add simply the first role {Qt::DisplayRole, "display"} to my roleNames and after that my specified roleNames for the other columns.
To different the roles to show the correct data yout will reimplement data(...) and figure it out, which roleName the ui be asking for. That's all -
F freaksdd has marked this topic as solved on