[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
This commit is contained in:
Matthias Kuhn 2014-10-15 16:21:00 +02:00
parent cd59091b9c
commit 3d9ba705de
2 changed files with 12 additions and 0 deletions

View File

@ -105,6 +105,10 @@ void QgsTextEditWrapper::initWidget( QWidget* editor )
}
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
mWritablePalette = mLineEdit->palette();
mReadOnlyPalette = mLineEdit->palette();
mReadOnlyPalette.setColor( QPalette::Text, mWritablePalette.color( QPalette::Disabled, QPalette::Text ) );
}
}
@ -143,5 +147,11 @@ void QgsTextEditWrapper::setEnabled( bool enabled )
mPlainTextEdit->setReadOnly( !enabled );
if ( mLineEdit )
{
mLineEdit->setReadOnly( !enabled );
if ( enabled )
mLineEdit->setPalette( mWritablePalette );
else
mLineEdit->setPalette( mReadOnlyPalette );
}
}

View File

@ -55,6 +55,8 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
QTextEdit* mTextEdit;
QPlainTextEdit* mPlainTextEdit;
QLineEdit* mLineEdit;
QPalette mReadOnlyPalette;
QPalette mWritablePalette;
};
#endif // QGSTEXTEDITWRAPPER_H