#include "posteventfilter.h"
Q_OBJECT
public:
};
Q_OBJECT
public:
public slots:
pe.setColor(m_tl ? Qt::red : Qt::blue );
pe.setWidth(3);
p.setPen(pe);
p.
setRenderHint(QPainter::Antialiasing);
if(m_tl){
p.drawLine(0,0, w->width(), w->height());
} else {
p.drawLine(w->width(), 0, 0, w->height());
}
return false;
}
return false;
}
private:
bool m_tl;
};
#include <QApplication>
int main(int argc, char **argv){
Dummy d(true);
Dummy u(false);
PushButton pb;
pb.setText("TESTING");
pb.installPostEventFilter(&d);
pb.installPostEventFilter(&u);
pb.show();
return app.exec();
}
#include "posteventfilter.h"
class PushButton : public QPushButton {
Q_OBJECT
WW_POSTEVENTFILTER(QPushButton)
public:
PushButton(QWidget *parent=0) : QPushButton(parent){}
};
class Dummy : public QObject {
Q_OBJECT
public:
Dummy(bool tl, QObject *parent=0) : QObject(parent){ m_tl = tl;}
public slots:
virtual bool postEventFilter(QObject *o, QEvent *e){
if(e->type()==QEvent::Paint){
QWidget *w = (QWidget*)o;
QPainter p(w);
QPen pe = p.pen();
pe.setColor(m_tl ? Qt::red : Qt::blue );
pe.setWidth(3);
p.setPen(pe);
p.setRenderHint(QPainter::Antialiasing);
if(m_tl){
p.drawLine(0,0, w->width(), w->height());
} else {
p.drawLine(w->width(), 0, 0, w->height());
}
return false;
}
return false;
}
private:
bool m_tl;
};
#include <QApplication>
int main(int argc, char **argv){
QApplication app(argc, argv);
Dummy d(true);
Dummy u(false);
PushButton pb;
pb.setText("TESTING");
pb.installPostEventFilter(&d);
pb.installPostEventFilter(&u);
pb.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks