PDA

View Full Version : CustomListWidgetItem setData -> call itemUpdated signal



JuanMO
12th August 2010, 16:41
Hello,

I have a CustomListWidgetItem and override the setData for my data, but I need to let the list know when the user data is changed.
Looking into the QT code I found that in the base class ( QListWidgetItem ) a signal is sent, through the QListModel , which it is not accessible.



class CustomListWidgetItem : public QListWidgetItem
{
...
void setData( int role, const QVariant & value )
{
switch(role)
{
case Qt::UserRole:
item = value.value<Item>();
UpdateDurationTimer();
if (QListModel *model = (listWidget() ? qobject_cast<QListModel*> (listWidget()->model()) : 0))
{
model->itemChanged(this); // This code is not accessible
}
break;
default:
QListWidgetItem::setData(role , value);
break;
}
}
....
}


Is there any elegant thing to do to emit that signal from the derived class? As walk around I could create an object and call base::setData to let the base do all the work but I don't like to duplicate unnecessary data

Thanks in advance

pervlad
12th August 2010, 20:21
If you need custom model/view, maybe you should reconsider using QListWidget and use QListView and QListModel instead.
In order to make custom model view development flexible there is model/view framework in Qt. It is very well documented see: Model/View Programming (http://doc.trolltech.com/4.6/model-view-programming.html) and An Introduction to Model/View Programming (http://doc.qt.nokia.com/4.6/model-view-introduction.html).