Correctly received the message from the input box in the Qt property control.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.