views:

412

answers:

2

Hi..

i am new to QT, i tried lot searching samples of how to get the button paint event in QT.. i am not getting 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

+2  A: 

You need to subclass QPushButton and reimplement paintEvent().

Kyle Lutz
hey, i tried by doing subclassing.. still i m not able to get the event.. i have updated the code in my post please look into it and tell me what is missing
Shadow
A: 
  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.

e8johan
ya.. i got it.. in QT for which control we need to crate delegate?i know listview one but rest i dont no?..y not for button? what is the idea behind it?
Shadow
well, only item views (list, table and tree view) have delegates. All widgets are meant to be sub-classed.
e8johan