Here is a real-world example of how this is done, and I need to understand how it's done. If you have used Qt before then this code should make sense.
Code:
#include <QApplication>
#include <QPushButton>
#include <QPainter>
#include <QPaintEvent>
class mBut : public QPushButton{
public:
void paintEvent(QPaintEvent *event){
QPainter painter(this);
painter.drawEllipse(2,2,100,25);
};
};
int main(int argc, char *argv[]){
QApplication app(argc, argv);
mBut *p = new mBut();
p->show();
return app.exec();
}
If you are on linux with Qt you can compile it with this:
Code:
g++ -o main main.cpp `pkg-config --cflags --libs QtGui`
mBut is my derived class. It inherits QPushButton and implements it's own version of paintEvent(). When my widget is shown, mBut:: paintEvent() is automatically called. mBut is derived from QPushButton, which is derived from QAbstractButton, which is derived from QWidget. paintEvent() is a protected virtual function in QWidget.