Skip to content

Commit f334961

Browse files
committed
Change button color when picking around
So that we have a consistent behavior with the Sample Color action.
1 parent 948452b commit f334961

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/gui/qgscolorbutton.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,7 @@ void QgsColorButton::mouseMoveEvent( QMouseEvent *e )
231231
{
232232
if ( mPickingColor )
233233
{
234-
//currently in color picker mode
235-
if ( e->buttons() & Qt::LeftButton )
236-
{
237-
//if left button depressed, sample color under cursor and temporarily update button color
238-
//to give feedback to user
239-
QScreen *screen = findScreenAt( e->globalPos() );
240-
if ( screen )
241-
{
242-
setButtonBackground( sampleColor( e->globalPos() ) );
243-
}
244-
}
234+
setButtonBackground( sampleColor( e->globalPos() ) );
245235
e->accept();
246236
return;
247237
}
@@ -294,7 +284,8 @@ void QgsColorButton::stopPicking( QPoint eventPos, bool samplingColor )
294284

295285
if ( !samplingColor )
296286
{
297-
//not sampling color, nothing more to do
287+
//not sampling color, restore old color
288+
setButtonBackground( mCurrentColor );
298289
return;
299290
}
300291

@@ -686,6 +677,8 @@ void QgsColorButton::pasteColor()
686677
void QgsColorButton::activatePicker()
687678
{
688679
//activate picker color
680+
// Store current color
681+
mCurrentColor = mColor;
689682
QApplication::setOverrideCursor( QgsApplication::getThemeCursor( QgsApplication::Cursor::Sampler ) );
690683
grabMouse();
691684
grabKeyboard();

src/gui/qgscolorbutton.h

+4
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ class GUI_EXPORT QgsColorButton : public QToolButton
411411
QgsColorSchemeRegistry *mColorSchemeRegistry = nullptr;
412412

413413
QColor mDefaultColor;
414+
415+
//! Store current color when start picking
416+
QColor mCurrentColor;
417+
414418
QString mContext;
415419
bool mAllowOpacity = false;
416420
bool mColorSet = false;

0 commit comments

Comments
 (0)