Actually, now that I give it a try I'm not even able to reproduce the problem. This works just fine for me (with both Qt 4.3.3 and a couple of weeks old snapshot of Qt 4.4):
// main.cpp
#include <QtGui>
{
public:
QWidget* createEditor
(QWidget* parent,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
QLineEdit* lineEdit
= dynamic_cast<QLineEdit
*>
(editor
);
if (lineEdit)
{
lineEdit->setCompleter(completer);
}
return editor;
}
};
int main(int argc, char* argv[])
{
table.setItemDelegate(new ItemDelegate(&table));
table.show();
return app.exec();
}
// main.cpp
#include <QtGui>
class ItemDelegate : public QItemDelegate
{
public:
ItemDelegate(QObject* parent = 0) : QItemDelegate(parent) { }
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QWidget* editor = QItemDelegate::createEditor(parent, option, index);
QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(editor);
if (lineEdit)
{
QStringList stringList = QStringList() << "foo" << "bar" << "baz";
QCompleter* completer = new QCompleter(stringList, lineEdit);
lineEdit->setCompleter(completer);
}
return editor;
}
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTableWidget table(4, 4);
table.setEditTriggers(QAbstractItemView::AllEditTriggers);
table.setItemDelegate(new ItemDelegate(&table));
table.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Doesn't it work for you?
Bookmarks