qpushbutton竖向文字
发布网友
发布时间:2023-03-14 15:31
我来回答
共1个回答
热心网友
时间:2023-10-23 04:42
自己看,不解释。
#include <QtGui>
class Widget : public QWidget
{
public:
Widget(QWidget *parent = 0): QWidget(parent){}
void paintEvent(QPaintEvent *)
{
QPainter p(this);
#if 1
QTextDocument document;
document.setHtml("<br>T<br>e<br>s<br>t<br>");
document.drawContents(&p);
#else
drawRotatedText(&p, 90, width() / 2, height() / 2, "The vertical text");
#endif
}
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();
}
};
int main(int argc, char **argv)
{
QApplication a(argc, argv);
Widget w;
w.resize(200,200);
QString string = "test ";
QLabel label;
label.setText(string);
label.show();
w.show();
return a.exec();
}