30
30
#include < QToolButton>
31
31
#include < QMenu>
32
32
#include < QDrag>
33
+ #include < QRectF>
34
+ #include < QLineF>
33
35
34
36
#include < cmath>
35
37
@@ -1017,14 +1019,18 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
1017
1019
QColor color = QColor ( mCurrentColor );
1018
1020
color.setAlpha ( 255 );
1019
1021
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 );
1021
1027
painter.setPen ( pen );
1022
1028
painter.setBrush ( Qt::NoBrush );
1023
1029
1024
1030
// draw background ramp
1025
1031
for ( int c = 0 ; c <= maxValue; ++c )
1026
1032
{
1027
- int colorVal = componentRange () * static_cast <double >( c ) / maxValue;
1033
+ int colorVal = static_cast < int >( componentRange () * static_cast <double >( c ) / maxValue ) ;
1028
1034
// vertical sliders are reversed
1029
1035
if ( mOrientation == QgsColorRampWidget::Vertical )
1030
1036
{
@@ -1040,12 +1046,12 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
1040
1046
if ( mOrientation == QgsColorRampWidget::Horizontal )
1041
1047
{
1042
1048
// horizontal
1043
- painter.drawLine ( c + mMargin , mMargin , c + mMargin , height () - mMargin - 1 );
1049
+ painter.drawLine ( QLineF ( c + mMargin , mMargin , c + mMargin , height () - mMargin - 1 ) );
1044
1050
}
1045
1051
else
1046
1052
{
1047
1053
// vertical
1048
- painter.drawLine ( mMargin , c + mMargin , width () - mMargin - 1 , c + mMargin );
1054
+ painter.drawLine ( QLineF ( mMargin , c + mMargin , width () - mMargin - 1 , c + mMargin ) );
1049
1055
}
1050
1056
}
1051
1057
}
@@ -1056,7 +1062,7 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
1056
1062
QBrush checkBrush = QBrush ( transparentBackground () );
1057
1063
painter.setBrush ( checkBrush );
1058
1064
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 ) );
1060
1066
QLinearGradient colorGrad;
1061
1067
if ( mOrientation == QgsColorRampWidget::Horizontal )
1062
1068
{
@@ -1076,7 +1082,7 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
1076
1082
colorGrad.setColorAt ( 1 , opaque );
1077
1083
QBrush colorBrush = QBrush ( colorGrad );
1078
1084
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 ) );
1080
1086
}
1081
1087
1082
1088
if ( mOrientation == QgsColorRampWidget::Horizontal )
@@ -1095,12 +1101,12 @@ void QgsColorRampWidget::paintEvent( QPaintEvent *event )
1095
1101
else
1096
1102
{
1097
1103
// 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 ();
1099
1105
painter.setBrush ( Qt::white );
1100
1106
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 ) );
1102
1108
painter.setPen ( Qt::black );
1103
- painter.drawLine ( mMargin , ypos, width () - mMargin - 1 , ypos );
1109
+ painter.drawLine ( QLineF ( mMargin , ypos, width () - mMargin - 1 , ypos ) );
1104
1110
}
1105
1111
}
1106
1112
0 commit comments