Hope someone can help me here. I have a QTableView for which I use my own QSortFilterProxyModel and own Delegate which is based on QStyledItemDelegate. My issue is in the Delegates::paintEvent()<br>I get core dumps if I have the following (Not using a proxy filter it works by the way):<br>
<br>void DataDelegate::paint(QPainter *painter,<br> const QStyleOptionViewItem &option,<br> const QModelIndex &index) const<br>{<br> QStandardItem *item = 0;<br> if (!index.isValid()) {<br>
qWarning() << "Invalid index" << __FILE__ << __LINE__;<br> return;<br> }<br> QStyledItemDelegate::paint(painter,option,index); <br> QStandardItemModel *m = (QStandardItemModel *) index.model();<br>
bool isWatched = index.data(Qt::UserRole+4).toBool();<br> if ( (isWatched) && (index.column() == 0)) {<br> item = (QStandardItem *) m->itemFromIndex(index); // <--------------- CORE DUMPS HERE------------------<br>
if (!item) {<br> return;<br> } <br> .// continue to do some custom painting...<br>------------------------------------------------------------------------------------------------------------------------<br>
<br>
Now if I do something like this:<br>void DataDelegate::paint(QPainter *painter,<br> const QStyleOptionViewItem &option,<br> const QModelIndex &proxyIndex) const<br>{<br> QStandardItem *item = 0;<br>
if (!proxyIndex.isValid()) {<br> qWarning() << "Invalid proxy index" << __FILE__ << __LINE__;<br> return;<br> }<br> QStyledItemDelegate::paint(painter,option,proxyIndex); <br> if (!proxyFilter) { // store in Delegate class and is pointer to a class derived from QSortFilterProxyModel<br>
qWarning() << "Invalid model for data delegate" << __FILE__ << __LINE__;<br> return;<br> }<br> QModelIndex index = proxyFilter->mapToSource(proxyIndex);<br> if (!index.isValid()) {<br>
// qWarning() << "Invalid index for data delegate" << __FILE__ << __LINE__;<br> return;<br> }<br> QStandardItemModel *m = (QStandardItemModel *) index.model();<br> bool isWatched = index.data(Qt::UserRole+4).toBool();<br>
if ( (isWatched) && (index.column() == 0)) {<br> item = (QStandardItem *) m->itemFromIndex(index); // <br> if (!item) {<br> return;<br> } <br> // continue to do some custom painting....<br><br>
<br>This works, with the following ugly exception. I get a lot of run time warnings<br>" QSortFilterProxy Model: index from wrong model passed to mapToSource" <br><br>Despite these warnings I doI get my custom painting to occur. I would like to figure out a way to do it right so that I do not get thousands of these warning messages at runitme. <br>
<br>Any suggestions on how to properly do a Delegate::paint() on a QTableView with a custom QSortFilterProxyModel is greatly appreciated.<br><br><br>-David<br>