Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QLabel and image antialiasing

QLabel and image antialiasing

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    v8671
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      V 1 Reply Last reply
      3
      • mrjjM mrjj

        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.

        V Offline
        V Offline
        v8671
        wrote on last edited by
        #3

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

        VRoninV 1 Reply Last reply
        0
        • V v8671

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

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          @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;
          };
          

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          4
          • V Offline
            V Offline
            v8671
            wrote on last edited by
            #5

            Thanks Vronin , that worked flawlessly

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved