How to get data from sqlquery that result 3 columns in a row and show only 1 Colum and use the other columns data
-
wrote on 2 Apr 2012, 12:13 last edited by
[quote author="umen242" date="1333367911"]no its the opposite, the data function is in the QSqlQueryModel.
i dont understand this :
@"...so you can still query these from the data method of proxy model...."@how ? where ?
do you mean i need to implement the data method of the proxy ?[/quote]
See the edit to my post above for an example. -
wrote on 2 Apr 2012, 12:15 last edited by
Thanks very much i will try it now
-
wrote on 2 Apr 2012, 12:21 last edited by
Note that this example does not try to modify any data. It just changes whatever it tells the user of the model is the data in it. Also note that I did not implement setData(). If you need to support setData too (for this role), things will quickly become more complicated...
-
wrote on 2 Apr 2012, 12:30 last edited by
hi i tryed you example , and there is 2 problems and that i dont understand
first one is that when it is:
@if (index.column() == 0 && role == Qt::UserRole) {@
it never enter the if , but when i change it to
@if (c == 0 && role == Qt::DisplayRole) {@it does Enter , but as expected the joined string is displayed in the row displayRole
how can i put it in the UserRole? -
wrote on 2 Apr 2012, 12:34 last edited by
Of course it is not entered, it is only entered when the UserRole is actually requested. That is how it ends up "in" the display role. The role is only the argument you pass to the data() function. Nothing more, nothing less. The normal delegates don't query for the UserRole (they only need the standard roles).
-
wrote on 2 Apr 2012, 12:51 last edited by
ok so how do i trigger it to be requested ? so i finally could set it
-
wrote on 2 Apr 2012, 12:58 last edited by
You simply request the data manually, where you need it. I assume you set this dat to the userRole for a reason, right? And that reason is presumably that you need this bit of information somewhere. So, how about actually requesting the data where you need it? It would be as simple as getting the right QModelIndex (that is: an index pointing to your proxy model; your view may supply it), and calling data(Qt::UserRole) on it.
-
wrote on 2 Apr 2012, 13:20 last edited by
finally !
this wasn't trivial at all man . its working thanks to you .
thanks!
21/28