开发者

How to get the paint event for Buttons in QT

i am new to QT, i tried lot searching samples of how to get the button paint event in QT.. i am not gett开发者_高级运维ing the way to do it..

how to set the delegates for pushbutton in QT?. how to get the paint event for pushbutton?

i read so many articles, it says we can get the paint event of button we can customize too. but i didnt get the piece of code how to get the paint event..

i try doing this sample, by sub classing still i am not getting event. please tell me whre m i wrong

  class Mybutton:QPushButton
    {
public:
    Mybutton(QObject *parent = 0){}
    void paintEvent ( QPaintEvent * );

    };




void Mybutton::paintEvent(QPaintEvent* Paint)
    {

    Paint->rect();

    }



int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QPushButton *Newbutton = new QPushButton();
    Newbutton->move(20,30);
    Newbutton->show();



    return a.exec();
}

still i am not able to get the events.

please helpe me in this.

Thanks


You need to subclass QPushButton and reimplement paintEvent().


  1. Subclass QPushButton, e.g. class MyButton : public QPushButton.... You seem to miss public.

  2. the paintEvent is a protected method, so your public override will not work well.

  3. This is not referred to as creating a delegate for QPushButton. What you are doing is that you are sub-classing it and re-implementing its paintEvent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜