HI, I have the following strange behaviour: I created a QListView whose elements are delegates. The delegate contains a button implemented this way:

Qt Code:
  1. void ItemDelegate::paint ( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
  2. {
  3. ...
  4. button.rect = buttonRect;
  5. button.features |= QStyleOptionButton::Flat;
  6. button.state = _state | QStyle::State_Enabled;
  7. QApplication::style()->drawControl(QStyle::CE_PushButton, &button, painter);
  8. ...
  9. }
  10.  
  11. bool ItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
  12. {
  13. if( event->type() == QEvent::MouseButtonPress ||
  14. event->type() == QEvent::MouseButtonRelease ) {
  15. } else {
  16. _state = QStyle::State_Raised;
  17. return true;
  18. }
  19.  
  20. ...
  21. QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
  22. if( !buttonRect.contains( mouseEvent->pos()) ) {
  23. _state = QStyle::State_Raised;
  24. return true;
  25. }
  26.  
  27. if( event->type() == QEvent::MouseButtonPress) {
  28. _state = QStyle::State_Sunken;
  29. } else if( event->type() == QEvent::MouseButtonRelease) {
  30. _state = QStyle::State_Raised;
  31. // call slot
  32. }
  33. }
To copy to clipboard, switch view to plain text mode 

It works fine except that the first time (after starting the application) I click any button, all buttons show the State_Sunken; all others clicks, after the first one, are normals: only the clicked button show the sunken/raised effect.

Do you have any explaination for this?

Very thanks.