c++ - Qt: creating an "svg image button" -
I'm new to QT so please excuse my ignorance.
I have a 'svg image button' with a QSizePolicy ::: The part that works for both horizontal and vertical works when the size of the window changes, the button grows and I am fine How do I ... But the image inside the button stays in the same size. I want to scale the image with the button I tried to overload resizeEvent, and call it at setImageSize, but it is infinitely recursive.
#ifndef SVGPUSHBUTTON_H # defined SVGPUSHBUTTON_H #include & lt; QtGui & gt; Square SVGPushButton: Public QPushButton {Public: SVGPushButton (QString path, QString name = ""); ~ SVGPushButton (); Zero resize event (QResizeEvent * event); Private:}; #endif // SVGPUSHBUTTON_H # included "SVGPushButton.h" SVGPushButton :: SVGPushButton (QString svgPath, QString name): QPushButton (name) {QIcon Icon (svgPath); SetSizePolicy (QSizePolicy :: Favorites, QSizePolicy :: Favorites); SetFlat (true); SetIcon (icon); } SVGPushButton :: ~ SVGPushButton () {} Zero SVGPushButton :: resizeEvent (QResizeEvent * Event) {Set Inks (event-> Size ()); }
In this way I finally resolve it:
SVGPushButton :: SVGPushButton (QString svgPath, QString name): QPushButton () {setSizePolicy (QSizePolicy :: Favorites, QSizePolicy :: Favorites); QSvgWidget * icon = new QSvgWidget (svgPath, this); SetLayout (new QHBoxLayout (this)); Layout () - & gt; Anchor (icon); }
Comments
Post a Comment