diff --git a/src/widgets/lineedit.cpp b/src/widgets/lineedit.cpp index 718627e4a..5d524a675 100644 --- a/src/widgets/lineedit.cpp +++ b/src/widgets/lineedit.cpp @@ -119,7 +119,6 @@ void ExtendedEditor::Paint(QPaintDevice* device) { } } else { clear_button_->setVisible(has_clear_button_); - Resize(); } } @@ -143,16 +142,19 @@ LineEdit::LineEdit(QWidget* parent) ExtendedEditor(this) { connect(reset_button_, SIGNAL(clicked()), SIGNAL(Reset())); + connect(this, SIGNAL(textChanged(QString)), SLOT(text_changed(QString))); } -void LineEdit::set_text(const QString& text) { - QLineEdit::setText(text); - - // For some reason Qt will detect any text with LTR at the end as LTR, so instead - // compare only the first character - if (!text.isEmpty()) { +void LineEdit::text_changed(const QString& text) { + if (text.isEmpty()) { + // Consider empty string as LTR + set_rtl(false); + } else { + // For some reason Qt will detect any text with LTR at the end as LTR, so instead + // compare only the first character set_rtl(QString(text.at(0)).isRightToLeft()); } + Resize(); } void LineEdit::paintEvent(QPaintEvent* e) { diff --git a/src/widgets/lineedit.h b/src/widgets/lineedit.h index 615b8b74a..e730ae29d 100644 --- a/src/widgets/lineedit.h +++ b/src/widgets/lineedit.h @@ -103,7 +103,7 @@ public: // ExtendedEditor void set_focus() { QLineEdit::setFocus(); } QString text() const { return QLineEdit::text(); } - void set_text(const QString& text); + void set_text(const QString& text) { QLineEdit::setText(text); } void set_enabled(bool enabled) { QLineEdit::setEnabled(enabled); } protected: @@ -114,6 +114,9 @@ private: bool is_rtl() const { return is_rtl_; } void set_rtl(bool rtl) { is_rtl_ = rtl; } +private slots: + void text_changed(const QString& text); + signals: void Reset(); };