From 0568fb9f428a84a344baaa5c53395db4b99f082c Mon Sep 17 00:00:00 2001 From: Prasanth Ullattil Date: Wed, 16 Dec 2009 13:14:12 +0100 Subject: Text cursor is not shown properly in line edits on Mac OS X. The mac stlye disables the blinking cursor when there is a selection in the line edit. The cursor is not shown back when this selection is removed (either by mouse or key press events). This patch watches the selection changed signal from the line control and updates the cursor status accordingly. Task-number: QTBUG-6378 Reviewed-by: Olivier Goffart --- src/gui/widgets/qlineedit.h | 1 + src/gui/widgets/qlineedit_p.cpp | 17 ++++++++++++++++- src/gui/widgets/qlineedit_p.h | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qlineedit.h b/src/gui/widgets/qlineedit.h index 594e488..3f159f6 100644 --- a/src/gui/widgets/qlineedit.h +++ b/src/gui/widgets/qlineedit.h @@ -288,6 +288,7 @@ private: #ifdef QT_KEYPAD_NAVIGATION Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool)) #endif + Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged()) }; #endif // QT_NO_LINEEDIT diff --git a/src/gui/widgets/qlineedit_p.cpp b/src/gui/widgets/qlineedit_p.cpp index 4437fef..23ab817 100644 --- a/src/gui/widgets/qlineedit_p.cpp +++ b/src/gui/widgets/qlineedit_p.cpp @@ -126,6 +126,21 @@ void QLineEditPrivate::_q_editFocusChange(bool e) } #endif +void QLineEditPrivate::_q_selectionChanged() +{ + Q_Q(QLineEdit); + if (control->preeditAreaText().isEmpty()) { + QStyleOptionFrameV2 opt; + q->initStyleOption(&opt); + bool showCursor = control->hasSelectedText() ? + q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q): + true; + setCursorVisible(showCursor); + } + + emit q->selectionChanged(); +} + void QLineEditPrivate::init(const QString& txt) { Q_Q(QLineEdit); @@ -138,7 +153,7 @@ void QLineEditPrivate::init(const QString& txt) QObject::connect(control, SIGNAL(cursorPositionChanged(int,int)), q, SLOT(_q_cursorPositionChanged(int,int))); QObject::connect(control, SIGNAL(selectionChanged()), - q, SIGNAL(selectionChanged())); + q, SLOT(_q_selectionChanged())); QObject::connect(control, SIGNAL(accepted()), q, SIGNAL(returnPressed())); QObject::connect(control, SIGNAL(editingFinished()), diff --git a/src/gui/widgets/qlineedit_p.h b/src/gui/widgets/qlineedit_p.h index dc648e8..f13dce2 100644 --- a/src/gui/widgets/qlineedit_p.h +++ b/src/gui/widgets/qlineedit_p.h @@ -128,7 +128,7 @@ public: #ifdef QT_KEYPAD_NAVIGATION void _q_editFocusChange(bool); #endif - + void _q_selectionChanged(); #ifndef QT_NO_COMPLETER void _q_completionHighlighted(QString); #endif -- cgit v0.12