Unsolved QSqlRelationalTableModel and QItemDelegate
-
Hello,
I have a column which is the ID of my users this column id is replace by name using relationaltable. When I edit that cell I want to type a name instead of ID after typing each letter new related item will be shown and their ID after clicking on proper item the name and ID painted in one cell.
Any suggestion to implement above...
-
Hi,
-
Is it possible to send other columns data or other variables to QSqlRelationalDelegate?
-
@alex20 said in QSqlRelationalTableModel and QItemDelegate:
Is it possible to send other columns data or other variables to QSqlRelationalDelegate?
What do you mean by that ?
-
For example I want to pass a variable to QSqlRelationalDelegate for example the database table name. Or a list that delegate should show to be selected by user.
-
@alex20
The tableQSqlRelationalDelegate
acts on is the one of the associatedQSqlRelationalTableModel
(via the view). You could access the table name via that, if you needed it.The list it shows is obtained via a foreign key:
Unlike the default delegate,
QSqlRelationalDelegate
provides a combobox for fields that are foreign keys into other tables. To use the class, simply callQAbstractItemView::setItemDelegate()
on the view with an instance ofQSqlRelationalDelegate
:If you want to supply your own list, you wouldn't bother with a
QSqlRelationalDelegate
. -
As you mentioned it will provide a combobox unfortunately my list is really long to be presented in that unfiltered combobox so I need to have a search box that help the user to filter the list and choose proper item. What do you suggest.
-
Do you mean something like a QCompleter ?
-
It can be some how.... think about google for example how to suggest you while you are searching. I want to do sth same but choosing the name of some primary ID.
-
Feed the completer with the database content.