Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QLabel and image antialiasing



  • Hello , excuse me if this forum is not pertinent to my question but i do not know where to post, i am using a qlabel to draw an image and actually i do not want it to be antialised when zoomed in, how can i achieve this ?
    thanks


  • Lifetime Qt Champion

    Hi and welcome to the forums
    It is a perfectly fine place to ask :)

    QLabel uses Qt::SmoothTransformation and there seems not to be a way to disable it
    https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlabel.cpp.html

    But you can easily make a custom widget with paintEvent and draw the image
    yourself not using smoothing.



  • @mrjj Holy cow, how can i draw a raw bitmap pixel by pixel ????



  • @v8671 said in QLabel and image antialiasing:

    Holy cow, how can i draw a raw bitmap pixel by pixel ????

    That's not what was suggested.

    @mrjj was talking of something like:

    class NonAntiAliasImage : public QWidget{
        Q_OBJECT
        Q_DISABLE_COPY(NonAntiAliasImage)
    public:
        explicit NonAntiAliasImage(QWidget* parent = Q_NULLPTR) 
            : QWidget(parent)
        {}
        const QPixmap& pixmap() const 
        {
            return m_pixmap;
        }
        void setPixmap(const QPixmap& px) 
        {
            m_pixmap = px;
            update();
        }
    protected:
        void paintEvent(QPaintEvent*)
        {
            QPainter painter(this);
            painter.setRenderHint(QPainter::Antialiasing, false);
            style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap.scaled(rect().size()));
        }
    private:
        QPixmap m_pixmap;
    };
    


  • Thanks Vronin , that worked flawlessly


Log in to reply