Qt-interest Archive, February 2007
Changeing the default editor for a delegate
Message 1 in thread
Hi,
I am using a QSqlRelationalModel as a source of data for a QTableView.
In this view I have applied the QSqlRelationalDelegate to join data
from one table to the other by a inner-join.
But I do not like the QDateTimeEdit delegate, I'd like to use a more
standard QLineEdit widget.
Searching in the documentation, I have found the QItemEditorFactory
class that seems to be perfect to do this task.
This is the code I have written:
QBoxLayout *lay = new QBoxLayout (QBoxLayout::TopToBottom, this);
view = new QTableView(this);
view->setModel (model);
lay->addWidget (view);
QSqlRelationalDelegate *delegate = new QSqlRelationalDelegate(view);
view->setItemDelegate(delegate);
QItemEditorCreatorBase *base = new
QStandardItemEditorCreator<QLineEdit>();
delegate->itemEditorFactory()->registerEditor(QVariant::DateTime,base );
But the apps crashes on the last line.
Where can I find documentation or example on this issue?
Thank you in advance.
Regards,
ing. Federico Fuga
--
[ signature omitted ]
Message 2 in thread
On 08.02.07 21:48:15, ing. Federico Fuga wrote:
> QItemEditorCreatorBase *base = new
> QStandardItemEditorCreator<QLineEdit>();
>
> delegate->itemEditorFactory()->registerEditor(QVariant::DateTime,base );
>
> But the apps crashes on the last line.
That means the delegate doesn't use such a factory. You may try
delegate->setItemEditorFactory( QItemEditorFactory::defaultFactory() )
before trying to change the factory, but I don't know wether that works.
Andreas
--
[ signature omitted ]
Message 3 in thread
Andreas,
On Thu, 8 Feb 2007 21:55:28 +0100
Andreas Pakulat <apaku@xxxxxx> wrote:
> That means the delegate doesn't use such a factory. You may try
> delegate->setItemEditorFactory( QItemEditorFactory::defaultFactory() )
>
> before trying to change the factory, but I don't know wether that
> works.
Great, it seems to work. Only the line won't compile because
defaultFactory() is a const *, but setItemEditorFactory wants a *, so I
created a new QItemEditorFactory(*QItemEditorFactory::defaultFactory()).
Thank you very very much for the hint!
Regards.
Federico Fuga
--
[ signature omitted ]