#include <QtGui>class InverseButton : public QPushButton{public: InverseButton(QWidget *parent = 0) : QPushButton(parent){} void paintEvent(QPaintEvent *pe) { QPushButton::paintEvent(pe); QPainter p(this); unsigned int len = fontMetrics().width(Text); //длина текста в пикселях unsigned int hei = fontMetrics().height(); //высота текста в пикселях drawRotatedText(&p, 180, (width()+len) / 2, (height()-hei) / 2, Text); } void setText(const QString &text){Text = text;} QString text(){return Text;} void drawRotatedText(QPainter *painter, float degrees, int x, int y, const QString &text) { painter->save(); painter->translate(x, y); painter->rotate(degrees); painter->drawText(0, 0, text); painter->restore(); }private: QString Text;};
#include <QtGui>class InverseButton : public QPushButton{ // ... void setText(const QString &text){Text = text;} QString text(){return Text;} // ...private: QString Text;};
drawRotatedText(&p, 180, (width()+len) / 2, (height()-hei) / 2, Text);