Index widgets are not actually part of the MVC concept but they are additional widgets laid on top of items in the view. They are expensive to maintain and one should avoid them. What kind of widgets would you like to put there?
Index widgets are not actually part of the MVC concept but they are additional widgets laid on top of items in the view. They are expensive to maintain and one should avoid them. What kind of widgets would you like to put there?
J-P Nurmi
I want to provide widgets in table cells, which consist of some text labels, some icons and an text edit field(date field), perhaps similar to the graphical interface of outlook calender...
Can you help me how to proceed ?
As for icons and text the default delegate should handle it fine. As for text edit fields - you'll be only editing one field at a time, so a slightly modified delegate returning a QTextEdit instance as the editor should be enough.
Do you mean, I have to use the different roles in my custom model to let the default delegate render the cells content ?
I tried to do so, but what made me first think of to try an different way, was, that with the decoration role I only could render one icon.
I am also not sure, would it be possible to have drag and drop support, if I implement the cells content in this way ?
Yes, that's correct.
If you want something non-standard, use a custom delegate. You'll be able to render whatever you want depending on the data contained in an item.I tried to do so, but what made me first think of to try an different way, was, that with the decoration role I only could render one icon.
Yes, itemviews support d&d.I am also not sure, would it be possible to have drag and drop support, if I implement the cells content in this way ?
So I have to implement the delegates paint() function to render my widget ?
Do I have to paint my icons, text labels, editor fields ? There must be an way, instead "manually painting" the widgets, or ?
A second wish:
I have to create spans inside my table view, these spans will have to contain what I described before. The QTableView has an method setSpan(), but how can I check in my custom view from my custom model, where it has to paint the spans?
Not widget, but item - yes.
You only paint the inactive state. In the editing state the delegate returns a real widget.Do I have to paint my icons, text labels, editor fields ?
I think you have to define what you mean by "widget". Icon is not a widget. Text is not a widget. So, what is a widget according to your definition?There must be an way, instead "manually painting" the widgets, or ?
Why should the model care about the span? It's just a set of data.I have to create spans inside my table view, these spans will have to contain what I described before. The QTableView has an method setSpan(), but how can I check in my custom view from my custom model, where it has to paint the spans?
I think "manually painting" the items may not be the succeeding way. If I'll use the delegates paint method, I have a simple bitmap, which is rendered inside the table view cell (in my case, inside the span). If the span will be very long, because of an longer event (calender event) the bitmap will be strechted and the text will be rendered not clean, you understand what I mean ?
The second problem is, the item will also have to contain an "active text edit field (date edit field for editing the event)" in the inactive state, how will this be possible with an rendered bitmap ?
Kind regards,
Alex
The model doesn't care. It doesn't have a concept of width or height. The delegate handles all that and it is given the rectangle that needs to be painted.
Render the date as text and react on clicking the cell - activate the editor and let the user edit the date. You don't need the spinbox to be active all the time. You can even render the looks of the box if you really need to.The second problem is, the item will also have to contain an "active text edit field (date edit field for editing the event)" in the inactive state, how will this be possible with an rendered bitmap ?
Ok, I tried your suggestion..., but nothing is displayed in my table cells, do you know, what I am doing wrong ? How do I have to implement the sizeHint() function ?
Qt Code:
void SchulungsplanDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex &index) { painter->save(); painter->fillRect(option.rect, option.palette.highlight()); // gets the cells size and draws the text inside painter->drawText(myRect, Qt::AlignCenter, "test"); painter->restore(); } /* QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index ) const { // ???????????? }To copy to clipboard, switch view to plain text mode
The signature doesn't match. QAbstractItemDelegate::paint() is a const method. So in fact you're not reimplementing but shadowing the function.
J-P Nurmi
ok, thanks a lot ! ;-)
Now it paints right... My second approach is, to paint an widget inside the table cell by grabbing the widget to an pixmap. This experiment seems to function, but the widget is VERY small inside the cell and you can only see the picture, if you resize the cell to a very, very large cell. I don't know why. The delegates painter got the right size of the cell.
painter->drawPixmap(option.rect, courseItem);
Do you know what I have to do ?
Qt Code:
void SchulungsplanDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex &index) const { if (index.column() == 3 && index.row() == 2) { painter->save(); painter->drawText(option.rect, Qt::AlignCenter, " 060505K1 8 von 01.01.2008 bis 10.01.2008 "); // painter->drawPixmap(option.rect, QPixmap("arrowOpen.png")); painter->restore(); } if (index.column() == 1 && index.row() == 1) { painter->save(); painter->drawPixmap(option.rect, courseItem); painter->restore(); } }To copy to clipboard, switch view to plain text mode
Bookmarks