Label.cpp 611 B

1234567891011121314151617181920212223242526272829
  1. #include "Label.h"
  2. #include <QPainter>
  3. PixmapLabel::PixmapLabel(QWidget *parent) : QLabel(parent), m_pixmap(QPixmap()) { }
  4. void PixmapLabel::setPixmap(const QPixmap &pixmap)
  5. {
  6. m_pixmap = pixmap;
  7. setFixedSize(pixmap.size());
  8. update();
  9. }
  10. QPixmap PixmapLabel::pixmap() const
  11. {
  12. return m_pixmap;
  13. }
  14. void PixmapLabel::paintEvent(QPaintEvent * /*event*/)
  15. {
  16. if (m_pixmap.isNull()) {
  17. return;
  18. }
  19. QPainter painter(this);
  20. painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
  21. painter.setPen(Qt::NoPen);
  22. painter.drawPixmap(rect(), m_pixmap);
  23. }