Important: Please read the Qt Code of Conduct -

How to stop an icon from getting stretched?

  • 0_1500668197560_Selection_131.png

    I'd like my icon (borrowed from Qt Creator) to be thin, not the standard 16x16 size. Is there any way to stop it from getting stretched?

  • Moderators

    @Vadi2 Call setIconSize() on your QComboBox should constrain it to the size you set as the maximum.

  • @ambershark said in How to stop an icon from getting stretched?:


    That's weird... says right there that smaller icons are not to be scaled up:

    This size is the maximum size that icons can have; icons of smaller size are not scaled up.

    Yet mine is!

  • I'm adding the icon to a QLineEdit by the way, not to the QComboBox.

    The idea didn't work unfortunately:

        auto icon = QIcon(QStringLiteral(":/icons/casesensitively-insensitive.png"));
        qDebug() << "first size:" << icon.availableSizes().first();
        auto action = new QAction(icon, tr("Whole Words Only"), this);
        lineEdit->addAction(action, QLineEdit::LeadingPosition);
    // first size: QSize(8, 16)

  • Moderators

    @Vadi2 I don't have the time right now to mess with it and see why so I'll just offer you a hacky solution. Create the icon as a 16x16 but only use 8x16 of it. Then it won't scale since it will be the expected size.

    I'm sure there's a Qt way to control things better but I don't know it off the top of my head and I don't have time to experiment.

  • 0_1500727667009_Peek 2017-07-22 14-42.gif

    That's what I've done, but it is huge and takes up way too much space. I'm unsatisfied with this.

  • Hi Vadi2,

    As I remember there is a Type (Enum) that defines the fit of Qt Resources in QWidgets. Had you see the documentation completely?

Log in to reply