IconWidget.cpp 494 B

123456789101112131415161718192021
  1. #include "IconWidget.h"
  2. #include <QPainter>
  3. IconWidget::IconWidget(FluentIconBase *ficon, QWidget *parent) : QWidget(parent), m_ficon(ficon) { }
  4. void IconWidget::setIcon(FluentIconBase *icon)
  5. {
  6. m_ficon.reset(icon);
  7. update();
  8. }
  9. void IconWidget::paintEvent(QPaintEvent * /*event*/)
  10. {
  11. if (!m_ficon) {
  12. return;
  13. }
  14. QPainter painter(this);
  15. painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
  16. m_ficon->render(&painter, rect());
  17. }