PDA

View Full Version : QTreeView with custom type



jajdoo
25th September 2011, 15:32
i am using the QTreeView with my custom model, and i need to know when the user triggers edit on the view, so i could send the data.
the problem is that QTreeView seems to send Qt::displayRole for both display and edit.
this is rather problematic, since i am also using some custom data types - i want to send a QString for displayRole and the real data for editRole (to send to my custom delegate)

is there a workaround this ? i'd prefer not to write an entire view just for this tiny detail...

jajdoo
25th September 2011, 21:27
so i've been sniffing around..
i found my solution, but a part of it is showing a combo box at all times by reimplementing paint event in my delegate:

void polly::RootDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if ( index.data().canConvert<ComboBoxData>() )
{
polly::ComboBoxData d = index.data().value<polly::ComboBoxData>();
QStyleOptionComboBox box;
box.currentText = d._items.at( d._selected ) ;
box.rect = option.rect;
box.editable = true;
box.state = QStyle::State_Active & QStyle::State_Enabled;

QApplication::style()->drawComplexControl(QStyle::CC_ComboBox,
&box, painter);
} else
QStyledItemDelegate::paint(painter, option, index);
}

problem now is that the "fake" combo box always turns out gray (disabled) and without text.. what did i do wrong?