Skip to content

Commit 3d9ba70

Browse files
committedOct 15, 2014
[editwidgets] text color for r/o line edits matches disabled color
Line edits are set to readonly to make it possible to copy values from disabled forms. Unfortunately Qt uses a style that makes them look editable even though they are not. This patches the text color to have the appearance that hints an uneditable widget. Fix #11413
1 parent cd59091 commit 3d9ba70

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎src/gui/editorwidgets/qgstexteditwrapper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ void QgsTextEditWrapper::initWidget( QWidget* editor )
105105
}
106106

107107
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
108+
109+
mWritablePalette = mLineEdit->palette();
110+
mReadOnlyPalette = mLineEdit->palette();
111+
mReadOnlyPalette.setColor( QPalette::Text, mWritablePalette.color( QPalette::Disabled, QPalette::Text ) );
108112
}
109113
}
110114

@@ -143,5 +147,11 @@ void QgsTextEditWrapper::setEnabled( bool enabled )
143147
mPlainTextEdit->setReadOnly( !enabled );
144148

145149
if ( mLineEdit )
150+
{
146151
mLineEdit->setReadOnly( !enabled );
152+
if ( enabled )
153+
mLineEdit->setPalette( mWritablePalette );
154+
else
155+
mLineEdit->setPalette( mReadOnlyPalette );
156+
}
147157
}

‎src/gui/editorwidgets/qgstexteditwrapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
5555
QTextEdit* mTextEdit;
5656
QPlainTextEdit* mPlainTextEdit;
5757
QLineEdit* mLineEdit;
58+
QPalette mReadOnlyPalette;
59+
QPalette mWritablePalette;
5860
};
5961

6062
#endif // QGSTEXTEDITWRAPPER_H

0 commit comments

Comments
 (0)
Please sign in to comment.