c++ - Is it possible to draw a colored rectangle on a pushButton? -
i want after choosing color qcolordialog put rectangle (as preview) on pushbutton , change color color have chosen.
the pushbutton before choosing color:
the pushbutton after choosing color:
is possible draw colored rectangle on pushbutton,
, how can (an example)?
create custom class derived of qpushbutton, example:
pushbutton.h
#ifndef pushbutton_h #define pushbutton_h #include <qpushbutton> class pushbutton : public qpushbutton { public: pushbutton(qwidget*parent=0); protected: void paintevent(qpaintevent *event); }; #endif // pushbutton_h
pushbutton.cpp
#include "pushbutton.h" #include <qpainter> pushbutton::pushbutton(qwidget *parent):qpushbutton(parent) { } void pushbutton::paintevent(qpaintevent *event) { qpushbutton::paintevent(event); qrect r(0, 0, width()/3, height()); r.moveto(rect().center()-r.center()); qpainter painter(this); painter.setbrush(qt::red); painter.drawrect(r); }
Comments
Post a Comment