How to resize and make the new size persistent in QSvgWidget?
Unsolved
General and Desktop
-
It's a continuation of this post. With that approach when I resize the pixmap, it gets pixelated so I've converted that into a
QSvgWidget
like this:ActionButton::ActionButton(const QString &fileName, QWidget *parent) : QSvgWidget(parent){ QFile f(fileName); f.open(QIODevice::ReadOnly | QIODevice::Text); m_document.setContent(f.readAll()); //QDomDocument m_document; changeColor(Qt::black); } void ActionButton::enterEvent(QEnterEvent*){ changeColor(Qt::blue); } void ActionButton::leaveEvent(QEvent*){ changeColor(Qt::black);} void ActionButton::mousePressEvent(QMouseEvent*){ changeColor(Qt::red); } void ActionButton::mouseReleaseEvent(QMouseEvent*){ emit triggered(); } void ActionButton::changeColor(const QColor &color){ m_document.elementsByTagName("path").at(0).toElement().setAttribute("fill", color.name()); resize(QSize(14, 14)); renderer()->load(m_document.toByteArray()); }
and this is what I get with those;
initially, those icons were not resized although I've a
changeColor(Qt::black)
call in the constructor. Later when I hover over those icons, they're resized. How to get those resized when they're displayed/rendered first? Is it possible to make the new size persistent and avoidresize(QSize(14, 14))
call inchangeColor
function? -
@Emon-Haque, took a while to figure out that
setMaximumSize(QSize(14, 14))
is what I need in the constructor!