[vlc-devel] [PATCH 1/2] qt: improve rendering of simple_pref icons for HiDpi

Pierre Lamot pierre at videolabs.io
Wed Nov 15 10:34:28 CET 2017


---
 modules/gui/qt/components/simple_preferences.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/modules/gui/qt/components/simple_preferences.cpp b/modules/gui/qt/components/simple_preferences.cpp
index 218630896f..e3c3b5c506 100644
--- a/modules/gui/qt/components/simple_preferences.cpp
+++ b/modules/gui/qt/components/simple_preferences.cpp
@@ -48,6 +48,7 @@
 #include <math.h>
 
 #define ICON_HEIGHT 48
+#define ICON_WIDTH 48
 
 #ifdef _WIN32
 # include <vlc_charset.h>
@@ -191,19 +192,21 @@ SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
     CONNECT( mapper, mapped(int), this, switchPanel(int) );
 
     QPixmap scaled;
+    qreal dpr = devicePixelRatioF();
 
 #define ADD_CATEGORY( button, label, ltooltip, icon, numb )                 \
     QToolButton * button = new QToolButton( this );                         \
     /* Scale icon to non native size outside of toolbutton to avoid widget size */\
     /* computation using native size */\
     scaled = QPixmap( ":/prefsmenu/" #icon ".png" )\
-             .scaledToHeight( ICON_HEIGHT , Qt::SmoothTransformation );\
+             .scaledToHeight( ICON_HEIGHT * dpr, Qt::SmoothTransformation );\
+    scaled.setDevicePixelRatio( dpr ); \
     button->setIcon( scaled );                \
     button->setText( label );                                               \
     button->setToolTip( ltooltip );                                         \
     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
-    button->setIconSize( QSize( scaled.width(), scaled.height() ) );          \
-    button->setMinimumWidth( 40 + scaled.width() );\
+    button->setIconSize( QSize( ICON_WIDTH, ICON_HEIGHT ) );          \
+    button->setMinimumWidth( 40 + ICON_WIDTH );\
     button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); \
     button->setAutoRaise( true );                                           \
     button->setCheckable( true );                                           \
-- 
2.14.1



More information about the vlc-devel mailing list