Thanx for reply, but I don't get it completely. I am looking at some examples in Qt Assistant and I can't catch when are those methods from QItemDelegate's class child called. Where is in my case, drawDisplay() method called?
Thanx for reply, but I don't get it completely. I am looking at some examples in Qt Assistant and I can't catch when are those methods from QItemDelegate's class child called. Where is in my case, drawDisplay() method called?
The delegate is used by the view to render items. So every time an item needs to be drawn, the delegate is called to do that. drawDisplay is called by paint() which in turn is called by the view.
The delegate is called automatically whenever the view feels like repainting an item.
Thanx for replies and sorry for stupid questions. What methods I need to reimplement in order to get my QItemDelegate to paint only 6th colum? Secondly, the painting depends on data (3 integer variables), as you can see on picture. How can I send those integers to QItemDelegate so the delegate can paint cell properly? Is there another way?
paint() and/or drawDisplay(), depending on which class you subclass. It also depends how you install the delegate. You can install it for a single column only or for all columns (then you have to reimplement paint() to call the base class implementation for columns other then 6th.
There are different ways to do this. I'd suggest using different item roles for each "colour" or setting a list of values as the data for the display role (setData(6, Qt::DisplayRole, QList<int>() << 1 << 2 << 3)) and then retrieve each value from within the delegate.Secondly, the painting depends on data (3 integer variables), as you can see on picture. How can I send those integers to QItemDelegate so the delegate can paint cell properly? Is there another way?
And I think it would be easier for you to subclass QItemDelegate and reimplement its paint() method than to go for drawDisplay().
Djony (4th December 2006)
How can I install delegate for just single column? I have decided to use QItemDelegate and to reimplement it's paint metod.
Maybe I've explained it wrong in previous postThe data shown in that "colored column" will not be changed by the user. It should be shown and "colored" by the delegate based upon the values that some other class reads from SQLITE 3 database. If you mean't the same thing, which methods from QItemDelegate I need to reimplement and how (in which direction, I don't have any idea)? How can I "send" those integers to delegate so he can color cells?
First thing to do is to browse QAbstractItemView docs and find the answer there.
I did.If you mean't the same thing,
My previous answer still stands. Please read about item roles and Qt MVC implementation.which methods from QItemDelegate I need to reimplement and how (in which direction, I don't have any idea)? How can I "send" those integers to delegate so he can color cells?
Thank you for replies. I've read documentation about item roles, models, views, delegates etc. If I understood you right, you are suggesting me to create model and reimplement it's setData() method and to store list of values in it (I am wondering at the moment which model class should I use, considering the fact that I am using QTableWidget. Should it be QStandardItemModel or I need to subclass QAbstractItemModel class?). After that, my delegate class will with data() get list of values and based on those values color the cell. That's cool.
But, when reimplementing paint() method I need to know cordinates (and dimensions) of whole cell, so I can paint properly. How can I retrieve cordinates (and dimensions) of whole cell in delegate class? (Maybe I've asked this before, but I don't get it...)
Again, thanx for replies![]()
If you use QTableWidget, then you don't need to touch the model, as QTableWidget already implements one for you. Just use QTableWidgetItem::setData() to store data and implement a custom delegate to display it.
Djony (14th December 2006)
OK, but can you please tell me how can I retrieve width of table cell in my delegate class?
QStyleOptionViewItem::rect
Bookmarks