PDA

View Full Version : QModelView update



bunjee
22nd April 2008, 19:38
Hey there,

I've searched a bit on the forum,

I'm not sure how to update the model from its delegate edit event.


bool ZeChatRoom_delegate::editorEvent(QEvent *event,
QAbstractItemModel *model,
const QStyleOptionViewItem &option,
const QModelIndex &index)
{
const ZeChatRoom_model* modelData = static_cast<const ZeChatRoom_model*>(index.model());
ZeChatRoom_data * chatData = index.data().value<ZeChatRoom_data *>();

if (event->type() == QEvent::MouseButtonDblClick)
{
//QMouseEvent *mev = (QMouseEvent*)event;

modelData->getService().
OpenChat(chatData->getRoomName() + '@' + modelData->getServer());

chatData->setClicked(true);

// Hey view could you update your display please ?

}
else if (event->type() == QEvent::MouseButtonRelease)
{
chatData->setClicked(false);

// Hey view could you update your display please ?
}
return false;
}

Thanks.

wysota
22nd April 2008, 20:38
The delegate should use QAbstractItemModel::setData to modify the model (or some other custom method the model provides and that emits dataChanged()). Emition of dataChanged() signal will cause the view to redraw the item.

bunjee
22nd April 2008, 22:02
Will do, thanks.