Hi
I had the same problem. schall_l's idea to subclass QItemEditorFactory is basically right, but it doesn't work, since QItemEditorFactory ist a base class with no functionality. You have to use the previously installed default factory (which is an instance of the private class QDefaultItemEditorFactory).
{
public:
static void installAsStandardFactory();
private:
};
class ItemEditorFactory : public QItemEditorFactory
{
public:
explicit ItemEditorFactory(const QItemEditorFactory* standardFactory);
virtual QWidget* createEditor(QVariant::Type type, QWidget* parent) const;
static void installAsStandardFactory();
private:
const QItemEditorFactory* m_standardFactory;
};
To copy to clipboard, switch view to plain text mode
, m_standardFactory(standardFactory)
{
}
{
switch (type)
{
{
ColorListEditor *cb = new ColorListEditor(parent);
cb->setFrame(false);
return cb;
}
default:
return m_standardFactory->createEditor(type, parent);
}
}
static void ItemEditorFactory::installAsStandardFactory()
{
}
ItemEditorFactory::ItemEditorFactory(const QItemEditorFactory* standardFactory)
: QItemEditorFactory()
, m_standardFactory(standardFactory)
{
}
QWidget* ItemEditorFactory::createEditor(QVariant::Type type, QWidget* parent) const
{
switch (type)
{
case QVariant::Color:
{
ColorListEditor *cb = new ColorListEditor(parent);
cb->setFrame(false);
return cb;
}
default:
return m_standardFactory->createEditor(type, parent);
}
}
static void ItemEditorFactory::installAsStandardFactory()
{
QItemEditorFactory::setDefaultFactory(new ItemEditorFactory(QItemEditorFactory::defaultFactory()));
}
To copy to clipboard, switch view to plain text mode
Just call ItemEditorFactory::installAsStandardFactory() in your code.
Happy Qoding.
Bookmarks