The modification method of string attribute in QtPropertyBrowser2.5 is an input box, And OnValueChange is sent every time you type a character. this is a disaster for the logic required by the editor. ogitor modified its source code to solve this problem:
In qteditorfactory. h
Add the following code to the QtLineEditFactory class, marked in red
Class QT_QTPROPERTYBROWSER_EXPORT QtLineEditFactory: public QtAbstractEditorFactory <QtStringPropertyManager>
{
Q_OBJECT
Public:
QtLineEditFactory (QObject * parent = 0 );
~ QtLineEditFactory ();
Protected:
Void connectPropertyManager (QtStringPropertyManager * manager );
QWidget * createEditor (QtStringPropertyManager * manager, QtProperty * property,
QWidget * parent );
Void disconnectPropertyManager (QtStringPropertyManager * manager );
Private:
QtLineEditFactoryPrivate * d_ptr;
Q_DECLARE_PRIVATE (QtLineEditFactory)
Q_DISABLE_COPY (QtLineEditFactory)
Q_PRIVATE_SLOT (d_func (), void slotPropertyChanged (QtProperty *, const QString &))
Q_PRIVATE_SLOT (d_func (), void slotRegExpChanged (QtProperty *, const QRegExp &))
Q_PRIVATE_SLOT (d_func (), void slotSetValue (const QString &))
Q_PRIVATE_SLOT (d_func (), void slotEditingFinished ())
Q_PRIVATE_SLOT (d_func (), void slotEditorDestroyed (QObject *))
};
In qteditorfactory. cpp
Class QtLineEditFactoryPrivate: public EditorFactoryPrivate <QLineEdit>
{
QtLineEditFactory * q_ptr;
Q_DECLARE_PUBLIC (QtLineEditFactory)
Public:
Void slotPropertyChanged (QtProperty * property, const QString & value );
Void slotRegExpChanged (QtProperty * property, const QRegExp & regExp );
Void slotSetValue (const QString & value );
Void slotEditingFinished ();
};
Void QtLineEditFactoryPrivate: slotEditingFinished ()
{
QObject * object = q_ptr-> sender ();
Const QMap <QLineEdit *, QtProperty *>: ConstIterator ecend = m_editorToProperty.constEnd ();
For (QMap <QLineEdit *, QtProperty *>: ConstIterator itEditor = m_editorToProperty.constBegin (); itEditor! = Ecend; ++ itEditor)
If (itEditor. key () = object ){
QtProperty * property = itEditor. value ();
QtStringPropertyManager * manager = q_ptr-> propertyManager (property );
If (! Manager)
Return;
QString value = static_cast <QLineEdit *> (itEditor. key ()-> text ();
Manager-> setValue (property, value );
Return;
}
}
QWidget * QtLineEditFactory: createEditor (QtStringPropertyManager * manager,
QtProperty * property, QWidget * parent)
{
QLineEdit * editor = d_ptr-> createEditor (property, parent );
QRegExp regExp = manager-> regExp (property );
If (regExp. isValid ()){
QValidator * validator = new QRegExpValidator (regExp, editor );
Editor-> setValidator (validator );
}
Editor-> setText (manager-> value (property ));
Connect (editor, SIGNAL (editingFinished ()),
This, SLOT (slotEditingFinished ()));
Connect (editor, SIGNAL (destroyed (QObject *)),
This, SLOT (slotEditorDestroyed (QObject *)));
Return editor;
}
In this way, an OnValueChange event can be generated after the Enter key or the input box loses focus.