Skip to content

Commit 67f5022

Browse files
authored
fix #15984 color ramps on MacOS (#9009)
fix #15984 color ramps on MacOS
1 parent 3adbed5 commit 67f5022

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/gui/qgscolorwidgets.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <QToolButton>
3131
#include <QMenu>
3232
#include <QDrag>
33+
#include <QRectF>
34+
#include <QLineF>
3335

3436
#include <cmath>
3537

@@ -1017,14 +1019,18 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
10171019
QColor color = QColor( mCurrentColor );
10181020
color.setAlpha( 255 );
10191021
QPen pen;
1020-
pen.setWidth( 0 );
1022+
// we need to set pen width to 1,
1023+
// since on retina displays
1024+
// pen.setWidth(0) <=> pen.width = 0.5
1025+
// see https://issues.qgis.org/issues/15984
1026+
pen.setWidth( 1 );
10211027
painter.setPen( pen );
10221028
painter.setBrush( Qt::NoBrush );
10231029

10241030
//draw background ramp
10251031
for ( int c = 0; c <= maxValue; ++c )
10261032
{
1027-
int colorVal = componentRange() * static_cast<double>( c ) / maxValue;
1033+
int colorVal = static_cast<int>( componentRange() * static_cast<double>( c ) / maxValue );
10281034
//vertical sliders are reversed
10291035
if ( mOrientation == QgsColorRampWidget::Vertical )
10301036
{
@@ -1040,12 +1046,12 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
10401046
if ( mOrientation == QgsColorRampWidget::Horizontal )
10411047
{
10421048
//horizontal
1043-
painter.drawLine( c + mMargin, mMargin, c + mMargin, height() - mMargin - 1 );
1049+
painter.drawLine( QLineF( c + mMargin, mMargin, c + mMargin, height() - mMargin - 1 ) );
10441050
}
10451051
else
10461052
{
10471053
//vertical
1048-
painter.drawLine( mMargin, c + mMargin, width() - mMargin - 1, c + mMargin );
1054+
painter.drawLine( QLineF( mMargin, c + mMargin, width() - mMargin - 1, c + mMargin ) );
10491055
}
10501056
}
10511057
}
@@ -1056,7 +1062,7 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
10561062
QBrush checkBrush = QBrush( transparentBackground() );
10571063
painter.setBrush( checkBrush );
10581064
painter.setPen( Qt::NoPen );
1059-
painter.drawRect( mMargin, mMargin, width() - 2 * mMargin - 1, height() - 2 * mMargin - 1 );
1065+
painter.drawRect( QRectF( mMargin, mMargin, width() - 2 * mMargin - 1, height() - 2 * mMargin - 1 ) );
10601066
QLinearGradient colorGrad;
10611067
if ( mOrientation == QgsColorRampWidget::Horizontal )
10621068
{
@@ -1076,7 +1082,7 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
10761082
colorGrad.setColorAt( 1, opaque );
10771083
QBrush colorBrush = QBrush( colorGrad );
10781084
painter.setBrush( colorBrush );
1079-
painter.drawRect( mMargin, mMargin, width() - 2 * mMargin - 1, height() - 2 * mMargin - 1 );
1085+
painter.drawRect( QRectF( mMargin, mMargin, width() - 2 * mMargin - 1, height() - 2 * mMargin - 1 ) );
10801086
}
10811087

10821088
if ( mOrientation == QgsColorRampWidget::Horizontal )
@@ -1095,12 +1101,12 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
10951101
else
10961102
{
10971103
//draw cross lines for vertical ramps
1098-
int ypos = mMargin + ( height() - 2 * mMargin - 1 ) - ( height() - 2 * mMargin - 1 ) * static_cast<double>( componentValue() ) / componentRange();
1104+
double ypos = mMargin + ( height() - 2 * mMargin - 1 ) - ( height() - 2 * mMargin - 1 ) * static_cast<double>( componentValue() ) / componentRange();
10991105
painter.setBrush( Qt::white );
11001106
painter.setPen( Qt::NoPen );
1101-
painter.drawRect( mMargin, ypos - 1, width() - 2 * mMargin - 1, 3 );
1107+
painter.drawRect( QRectF( mMargin, ypos - 1, width() - 2 * mMargin - 1, 3 ) );
11021108
painter.setPen( Qt::black );
1103-
painter.drawLine( mMargin, ypos, width() - mMargin - 1, ypos );
1109+
painter.drawLine( QLineF( mMargin, ypos, width() - mMargin - 1, ypos ) );
11041110
}
11051111
}
11061112

0 commit comments

Comments
 (0)