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. png image is blurred on QLabel

png image is blurred on QLabel

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.5k Views 1 Watching
  • 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.
  • JoeCFDJ Offline
    JoeCFDJ Offline
    JoeCFD
    wrote on last edited by JoeCFD
    #1

    If the QLabel size is smaller than the size of PNG image, the display of image(mainly texts) is blurred.
    No problem when the label size is same or bigger as the image size.

    QFile file(filename);
    QPixmap *pixmap = new QPixmap();
    if(!pixmap->load(filename))
    {
        delete pixmap;
        pixmap = Q_NULLPTR;
    }
    

    ui.label->setPixmap( pixmap->scaled( size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) );

    googled online and did not find the right solutions. Thanks for your help in advance.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      class MyImage : public QWidget
      {
      Q_OBJECT
      public:
      explicit MyImage(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, true);
      painter.setRenderHint(QPainter::TextAntialiasing, true);
      style()->drawItemPixmap(&painter, rect(), Qt::AlignCenter, m_pixmap.scaled(rect().size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
      }
      private:
      QPixmap m_pixmap;
      };

      also tried to use paintEvent of QWidget to display it. Got the same result.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shaan7
        wrote on last edited by
        #3

        It'll be useful if you can post screenshot of non-resized (and hence not blurred) and resized/blurred version of the image.
        Also, note that scaling down images will almost always suffer from quality loss.

        1 Reply Last reply
        1

        • Login

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