PDA

View Full Version : When using editorEvent in QItemDelegate, the QStyle::State_Selected doesnt arrive



boblatino
21st September 2010, 16:58
When using editorEvent in QItemDelegate, the QStyle::State_Selected doesn't arrive in the editorEvent but it does in paint. I'm using QStyleOptionViewItem.state.



bool InCallItemDelegate::editorEvent(QEvent * event, QAbstractItemModel * model
, const QStyleOptionViewItem & option, const QModelIndex & index )
{
if((option.state & QStyle::State_Selected) == QStyle::State_Selected)
{
//This does not arrive.
}
}

void InCallItemDelegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
if((option.state & QStyle::State_Selected) == QStyle::State_Selected)
{
//This works
}
}


Should I capture the selection in some other way? Could be a QT bug? Im using 4.7.0


Thanks
Ramiro

wysota
21st September 2010, 17:53
editorEvent() handles many types of events. Some of them have information about selection and some don't.

boblatino
21st September 2010, 18:54
I'm catching all the events in the example provided and I'm selecting a item in the UI. When I do that, the paint is called with the selection but the editorEvent doesn't. What could be happening? Should I register for some type of events like an eventFilter? I need the selection because I'm catching MouseButtonPress, MouseButtonRelease and I need to know if the clicked item is selected (because if its selected I do an action, else I change the selection).


Thanks
Ramiro

wysota
21st September 2010, 21:14
When I do that, the paint is called with the selection but the editorEvent doesn't.
Let me repeat myself, but only once. editorEvent() handles many types of events, not a particular one. You can't just look at one event which doesn't contain information about selection and say that editorEvent() doesn't have information about selection. Sometimes it does, sometimes it doesn't, it all depends on the type of event it is currently handling. It's a direct equivalent of QObject::event().