Skip to content

Commit 773e0d4

Browse files
committed
[gui] Fix color button where initially set color is same as default, but does not set background of button
1 parent 2d728d7 commit 773e0d4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/gui/qgscolorbutton.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ QgsColorButton::QgsColorButton( QWidget *parent, QString cdt, QColorDialog::Colo
4545
, mColorDialogOptions( cdo )
4646
, mAcceptLiveUpdates( true )
4747
, mTempPNG( NULL )
48+
, mColorSet( false )
4849
{
4950
connect( this, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
5051
}
@@ -134,7 +135,8 @@ void QgsColorButton::setColor( const QColor &color )
134135
QColor oldColor = mColor;
135136
mColor = color;
136137

137-
if ( oldColor != mColor )
138+
// handle when initially set color is same as default (Qt::black); consider it a color change
139+
if ( oldColor != mColor || ( mColor == QColor( Qt::black ) && !mColorSet ) )
138140
{
139141
setButtonBackground();
140142
if ( isEnabled() )
@@ -144,6 +146,7 @@ void QgsColorButton::setColor( const QColor &color )
144146
emit colorChanged( mColor );
145147
}
146148
}
149+
mColorSet = true;
147150
}
148151

149152
void QgsColorButton::setButtonBackground()

src/gui/qgscolorbutton.h

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class GUI_EXPORT QgsColorButton: public QPushButton
140140
QColorDialog::ColorDialogOptions mColorDialogOptions;
141141
bool mAcceptLiveUpdates;
142142
QTemporaryFile mTempPNG;
143+
bool mColorSet; // added in QGIS 2.1
143144

144145
private slots:
145146
void onButtonClicked();

0 commit comments

Comments
 (0)