View Full Version : Sub classing QListWidgetItem
Majdi
25th February 2009, 16:07
Hello,
I have small problem and I think its the last one to finish this project. I have I want to create Table view that contain items ( QListWidgetItem ). Each item should contain name, image and pointer to hold object from type ( QSqlQueryModel ).
I have to problem by item name and image. The only problem is to add to that Item a pointer can hold QSqlQueryModel object. I try to subclass QListWidgetItem and add the pointer but did not work
can anyone help me in this ?
thanks
jpn
25th February 2009, 16:40
Why don't you use the QSqlQueryModel with QListView?
Majdi
26th February 2009, 08:37
I don't want to used QListView because I'm not good with Model Based , But this is not the problem.
I create QListWidget, and I use it to hold Items. Each Item has name and icon. Now I want the item to hold QSqlQueryModel .
This list will be like history of all SQL quires, so when the user do a query it will be saved in that list as QSqlQueryModel object, When the user click on the icon , the query result will be read loaded in the box of result. so each time the user choose query from history , I just need to take the QSqlQueryModel object which saved in the items of the list and pass it to the table view which show the result.
because of that i want the item of the list which is from type QListWidgetItem to have ability to carry object from type QSqlQueryModel , and this is my problem :)
aamer4yu
27th February 2009, 18:30
A simpler approach to your problem would be as follows -
For the listWidgetItem, use setData to store the result in your defined role, say RESULT_ROLE.
Now use a custom delegate and override the drawDisplay as follows -
MyDelegate::drawDisplay(......)
{
QString result = text; // text is the argument string to draw
if(option.state & Qt::Selected) // if item is selected...
result = index.data(RESULT_ROLE);
QItemDelegate::drawDisplay(result....); // use result instead of text
}
Hope this works for you :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.