[vlc-devel] [PATCH] qt/pref: fix toolbar icon or text beeing cropped on Hi-DPI displays

pierre pierre at videolabs.io
Wed Sep 13 14:10:50 CEST 2017


On Wednesday, September 13, 2017 11:51:07 AM CEST Francois Cartegnie wrote:
> Le 13/09/2017 à 11:45, Pierre Lamot a écrit :
> >      button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );           
> >        \
> > 
> > -    button->setIconSize( QSize( icon_height + 40 , icon_height ) );      
> >   \ +    button->setIconSize( QSize( icon_height, icon_height ) );       
> >        \ +    button->setMinimumSize( QSize( icon_height + 40,
> > icon_height + 40 ) );  \
> Can't be correct due to the way HiDPI sizes now works.
> I don't think the fix belongs to there.

Actually this behavior can be reproduced quite easilly. The program below will 
produce the enclosed pictures at different DPI

QT_SCALE_FACTOR=1 ./QTooltip -> scale_1.png
QT_SCALE_FACTOR=2 ./QTooltip -> scale_2.png

This aside, it seems  unecessary to set the miminum height in my patch, I can 
obtain the expected behavior with:

> button->setMinimumWidth( icon_height + 40 );

instead of

> button->setMinimumSize( QSize( icon_height + 40, icon_height + 40 ) ); 

--------8<--------8<--------8<--------8<--------

#include <QApplication>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QToolButton>

int main(int argc, char *argv[])
{
    QApplication::setAttribute( Qt::AA_EnableHighDpiScaling );
    QApplication::setAttribute( Qt::AA_UseHighDpiPixmaps );
    QApplication a(argc, argv);

    QMainWindow w;

    QHBoxLayout* layout = new QHBoxLayout;

    QToolButton* btnOk = new QToolButton();
    //icon.png is 64x64
    btnOk->setIcon(QIcon(":/img/icon.png"));
    btnOk->setIconSize(QSize(40, 40));
    btnOk->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
    btnOk->setText("not cropped");

    QToolButton* btnKo = new QToolButton();
    btnKo->setIcon(QIcon(":/img/icon.png"));
    btnKo->setIconSize(QSize(120, 40));
    btnKo->setText("cropped");
    btnKo->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);

    layout->addWidget(btnOk);
    layout->addWidget(btnKo);

    QWidget* centralWidget = new QWidget;
    centralWidget->setLayout(layout);

    w.setCentralWidget(centralWidget);
    w.show();

    return a.exec();
}
-- 
Pierre Lamot
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scale_1.png
Type: image/png
Size: 11125 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170913/ef7920d7/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scale_2.png
Type: image/png
Size: 20707 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170913/ef7920d7/attachment-0001.png>


More information about the vlc-devel mailing list