PDA

View Full Version : Restrict QItemEditorFactory to one widget



pratham_shah
20th May 2013, 15:05
Hi,

I have a custom QDialog (say "MyDialog") with a QTableWidget to display my data.
Now in MyDialog constructor I have the following code



MyDialog::MyDialog(QWidget *parent) : QDialog(parent)
{
QItemEditorFactory *myFactory = new QItemEditorFactory;
QItemEditorCreatorBase *myEditorCreator = new QStandardItemEditorCreator<MyItemEditor>();
myFactory->registerEditor(QVariant::String, myEditorCreator );
QItemEditorFactory::setDefaultFactory(myFactory);

setupTable();
}


I have 2 queries regarding the code.
Firstly Who is responsible for deleting myFactory ?
Secondly, what is the scope of myFactory and hence the editor MyItemEditor ?
In other words will a different QTableWidget in some other place also use this factory ?

wysota
20th May 2013, 19:03
Firstly Who is responsible for deleting myFactory ?
Qt


Secondly, what is the scope of myFactory and hence the editor MyItemEditor ?
Scope of the factory is the whole application unless you delete it yourself. Scope of the editor is the time it takes to edit a single cell in the table.


In other words will a different QTableWidget in some other place also use this factory ?
Yes, since you have set it as default.

pratham_shah
21st May 2013, 07:06
So then how to restrict the QItemEditorFactory to one particular widget ?

ChrisW67
21st May 2013, 07:28
You create a QStyledItemDelegate that you apply to only the one view.

wysota
21st May 2013, 07:29
Apply a custom item delegate on the widget and set the item editor factory on that delegate directly instead of setting it as default.