ListView Delegate
-
I have ListView. In the Delegate I have painted fillrect at particular index once or twice as needed. I wanted help in how do I create widget i.e QLabel for every rect differently. Please advice.
-
Hi,
Something's not clear here, are you using widgets or Qt Quick ?
-
Hi,
I am using Widgets.I need to put three different widgets in single index in listview -
Hi,
In general you have to reimplement createEditor() and setEditorData on the delegate to create a Widget.
Could you show your code ?
-
for(int i = 0;i<m_numberOfSlots;i++)
{
int sheetCountPerSlot = index.data(Qt::UserRole).toInt();if(index.row()==i) { painter->setPen(slotPen); painter->drawRect(option.rect); for (int var = 0; var < sheetCountPerSlot; var++) { const_cast<QRect&>(r)= QRect(x,y,width,height); painter->setRenderHint(QPainter::Antialiasing,true); painter->setPen(sheetPen); painter->fillRect(r,Qt::blue); const_cast<QString&>(m_numberText) = QString::number(i)+"-"+QString::number(var); painter->setPen(sheetNumberPen); painter->drawText(r,m_numberText); x= x+width +10; } } }
In the above code I am painting rect at same index many times which i want.
So when in create editor I want render each rect to be Widget say (QLabel) so if there are 3 rects then when i click create editor is called so the clicked one should be QLabel. Please advice. -
Are you using the
paint()
method?In that case IMO is better to use
createEditor()
-
Yes I am using paint method