PDA

View Full Version : Delegate & widgets



zuck
11th August 2009, 14:41
Hi, I need to implement a delegate for a QListView widget which paints, for each item (taken from a sql table model), a pair composed by a QLabel and a QLineEdit instances.

How can i do it?



void MyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
// ... ??
}


I need "real widgets" instead of "painted-only widgets", so i can connect signals and slots for my specific logic.

Thanks for your help! :)

faldzip
11th August 2009, 18:31
you can use the WA_DontShowOnScreen widget attribute. you can make real widgets with that attribute set to true, then install eventFilter() on them and call update on proper index while you catch PaintEvent. in paint you can use QWidget::render() to render the widget (for me it is working to render it on a pixmap and than paint the pixmap in the view). Unfotunately you have to catch events like mouse in the editorEvent() and pass it to the proper widget, which require some work.

numbat
12th August 2009, 09:41
If you don't have too many rows, I think you can call QAbstractItemView::setIndexWidget. However, I don't know if this is recommended.