c++ - Create Custom Button -
i want create custom pushbutton without styling displays .png image.
i have tried creating pushbutton seticon method uses pushbutton silver styling want display image , have button.
also, tried using qaction
newact = new qaction(qicon(":/new/prefix1/images/appbar.close.png"),
but not display without toolbar.
any ideas how can work?
maybe code helps you. create qpushbutton, set icon , use code :
yourqpushbutton->setflat(true);
update :
mypushbutton.h:
#ifndef mypushbutton_h #define mypushbutton_h #include <qlabel> class mypushbutton : public qlabel { q_object public: explicit mypushbutton(qwidget *parent = 0); signals: void clicked(); protected: void mousereleaseevent(qmouseevent *ev); }; #endif // mypushbutton_h
mypushbutton.cpp
void mypushbutton::mousereleaseevent(qmouseevent *ev) { emit clicked(); }
how use :
mypushbutton btn; btn.setpixmap(qpixmap(":/rm.png")); qobject::connect(&btn, signal(clicked()), qapp, slot(quit())); btn.show();
you can add function mypushbutton
class more productive :)
void mypushbutton::seticon(qpixmap px, int w, int h) { setpixmap(px.scaled(w, h)); }
Comments
Post a Comment