Вот workaround.
spinboxdelegate.h:
C++ (Qt)
#ifndef SPINBOXDELEGATE_H
#define SPINBOXDELEGATE_H
#include <QItemDelegate>
class QComboBox;
class SpinBoxDelegate : public QItemDelegate
{
Q_OBJECT
public:
SpinBoxDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
bool eventFilter( QObject* editor, QEvent* event );
private Q_SLOTS:
void resetEditor();
private:
mutable QComboBox* editor_;
};
#endif // SPINBOXDELEGATE_H
spinboxdelegate.cpp:
C++ (Qt)
#include <QComboBox>
#include <QAbstractItemView>
#include <QEvent>
#include <QFocusEvent>
#include "spinboxdelegate.h"
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
: QItemDelegate(parent)
, editor_( 0 )
{
}
void SpinBoxDelegate::resetEditor()
{
editor_ = 0;
}
QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &/* index */) const
{
QComboBox* editor = new QComboBox(parent);
editor->addItem("aaa");
editor->addItem("bbb");
editor->addItem("ccc");
editor->view(); // we need this call to create popup
editor_ = editor;
connect( editor_, SIGNAL( destroyed() ), this, SLOT( resetEditor() ) );
return editor;
}
bool SpinBoxDelegate::eventFilter( QObject* o, QEvent* e )
{
if( e->type() == QEvent::FocusOut && o == editor_ &&
editor_->view()->isVisible() )
return true;
else
return QItemDelegate::eventFilter( o, e );
}
Но, имхо, держать интерактивную таблицу на сцене неправильно. Ещё неизвестно на какие проблемы напоришься.