덕분에 peppe입니다.
다음 하위 클래스는 포커스가있을 때 lineEdit 텍스트를 저장하고 텍스트가 변경 될 때마다 텍스트가 시작 텍스트와 동일한 지 확인하고 그렇지 않은 경우 textEditedCustom (QString)을 내 보냅니다.
헤더로 이동!
class customQLineEdit: public QLineEdit
{
Q_OBJECT
public :
explicit customQLineEdit(QWidget* parent = 0);
explicit customQLineEdit(const QString &str, QWidget* parent=0);
signals:
void textEditedCustom(const QString& text);
public slots:
void on_Text_Edited_custom(const QString& currentText);
protected:
QString previousText;
virtual void focusInEvent(QFocusEvent* e);
};
과 통화 당은 일부 그런
customQLineEdit::customQLineEdit(QWidget* parent):
QLineEdit(parent)
{
connect(this , SIGNAL(textEdited(QString)) ,
this , SLOT(on_Text_Edited_custom(QString)));
}
customQLineEdit::customQLineEdit(const QString &str, QWidget* parent):
QLineEdit(str , parent)
{
connect(this , SIGNAL(textEdited(QString)) ,
this , SLOT(on_Text_Edited_custom(QString)));
}
void customQLineEdit::focusInEvent(QFocusEvent* e)
{
previousText = text();
QLineEdit::focusInEvent(e);
}
void customQLineEdit::on_Text_Edited_custom(const QString& txt)
{
if(previousText != txt)
emit textEditedCustom(txt);
}
이
connect(nameLineEdit , SIGNAL(textEditedCustom(QString)) ,
this , SLOT(on_name_Changed(const QString &)));
서브 클래스처럼에 가입 재정의'focusInEvent'이있는 당신은 멤버 변수에 현재 텍스트를 복사 할 수 있습니다 ,'textChanged'를 당신이 비교할 슬롯에 스스로 연결하고 라인 편집이 실제로 수정되었는지 아닌지를 알려주는 신호를 내 보냅니다. – peppe
@peppe이 답변을 공식화하는 데주의합니까? T.Zak이 아닌 경우 : 자신의 질문에 대한 대답으로 이미 작성한 내용 (일부 세부 정보/코드 포함)을 작성하고 받아 들일 수있는 답변이 없으면 잘못이 아닙니다. – Hayt