Skip to content

Commit b49e940

Browse files
committed
Make color swatch list hi-dpi friendly
1 parent 9d4b80e commit b49e940

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/gui/qgscolorschemelist.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,12 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte
704704
}
705705

706706
QRect rect = option.rect;
707+
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
708+
const int cornerSize = iconSize / 6;
707709
//center it
708-
rect.setLeft( option.rect.center().x() - 15 );
709-
rect.setSize( QSize( 30, 30 ) );
710+
rect.setLeft( option.rect.center().x() - iconSize / 2 );
711+
712+
rect.setSize( QSize( iconSize, iconSize ) );
710713
rect.adjust( 0, 1, 0, 1 );
711714
//create an icon pixmap
712715
painter->save();
@@ -717,12 +720,12 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte
717720
//start with checkboard pattern
718721
QBrush checkBrush = QBrush( transparentBackground() );
719722
painter->setBrush( checkBrush );
720-
painter->drawRoundedRect( rect, 5, 5 );
723+
painter->drawRoundedRect( rect, cornerSize, cornerSize );
721724
}
722725

723726
//draw semi-transparent color on top
724727
painter->setBrush( color );
725-
painter->drawRoundedRect( rect, 5, 5 );
728+
painter->drawRoundedRect( rect, cornerSize, cornerSize );
726729
painter->restore();
727730
}
728731

@@ -738,9 +741,10 @@ QPixmap QgsColorSwatchDelegate::transparentBackground() const
738741

739742
QSize QgsColorSwatchDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const
740743
{
741-
Q_UNUSED( option );
742744
Q_UNUSED( index );
743-
return QSize( 30, 32 );
745+
746+
const int iconSize = Qgis::UI_SCALE_FACTOR * option.fontMetrics.width( 'X' ) * 4;
747+
return QSize( iconSize, iconSize * 32 / 30.0 );
744748
}
745749

746750
bool QgsColorSwatchDelegate::editorEvent( QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index )

src/gui/qgscompoundcolorwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ QgsCompoundColorWidget::QgsCompoundColorWidget( QWidget *parent, const QColor &c
6565
QgsSettings settings;
6666

6767
mSchemeList->header()->hide();
68-
mSchemeList->setColumnWidth( 0, 44 );
68+
mSchemeList->setColumnWidth( 0, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6 );
6969

7070
//get schemes with ShowInColorDialog set
7171
refreshSchemeComboBox();

src/gui/raster/qgscolorrampshaderwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ QgsColorRampShaderWidget::QgsColorRampShaderWidget( QWidget *parent )
6363

6464
mSwatchDelegate = new QgsColorSwatchDelegate( this );
6565
mColormapTreeWidget->setItemDelegateForColumn( ColorColumn, mSwatchDelegate );
66-
mColormapTreeWidget->setColumnWidth( ColorColumn, 50 );
66+
mColormapTreeWidget->setColumnWidth( ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
6767
mColormapTreeWidget->setContextMenuPolicy( Qt::CustomContextMenu );
6868
mColormapTreeWidget->setSelectionMode( QAbstractItemView::ExtendedSelection );
6969
connect( mColormapTreeWidget, &QTreeView::customContextMenuRequested, this, [ = ]( QPoint ) { contextMenu->exec( QCursor::pos() ); }

src/gui/raster/qgspalettedrendererwidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ QgsPalettedRendererWidget::QgsPalettedRendererWidget( QgsRasterLayer *layer, con
6666

6767
mSwatchDelegate = new QgsColorSwatchDelegate( this );
6868
mTreeView->setItemDelegateForColumn( QgsPalettedRendererModel::ColorColumn, mSwatchDelegate );
69-
mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, 50 );
69+
mTreeView->setColumnWidth( QgsPalettedRendererModel::ColorColumn, Qgis::UI_SCALE_FACTOR * fontMetrics().width( 'X' ) * 6.6 );
7070
mTreeView->setContextMenuPolicy( Qt::CustomContextMenu );
7171
mTreeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
7272
mTreeView->setDragEnabled( true );

0 commit comments

Comments
 (0)