If you subclass and reimplement paintEvent and don't call the base class implementation of the paintEvent from your implementation explicitely, then your handler will replace the base class event handler completely.
Look at this:
#include <QApplication>
#include <QLabel>
#include <QPainter>
class MyLabel
: public QLabel {public:
protected:
p.drawText(rect(), Qt::AlignCenter, "X");
}
};
int main(int argc, char **argv){
MyLabel lab;
lab.setText("Some completely custom text");
lab.show();
return app.exec();
}
#include <QApplication>
#include <QLabel>
#include <QPainter>
class MyLabel : public QLabel {
public:
MyLabel(QWidget *p=0) : QLabel(p){}
protected:
void paintEvent(QPaintEvent *){
QPainter p(this);
p.drawText(rect(), Qt::AlignCenter, "X");
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
MyLabel lab;
lab.setText("Some completely custom text");
lab.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
No matter what you set using QLabel::setText() you'll always see just an "X".
Bookmarks