void WgtText::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QString m_string("abcdefghijklmnopqrstuvwxy");
int font_size = 15;
float x0 = font_size * m_string.count() * 0.5;
int YSize = font_size * m_string.count() * 0.5;
for(int i=0; i<m_string.count(); i++)
{
// 按圆弧函数绘制
painter.save();
float tAlpha = i*3.14/m_string.count();
float tx = YSize*cos(tAlpha) + YSize;
float ty = YSize*sin(tAlpha);
painter.translate(tx, ty); // 文字的位置
painter.rotate(180*i/(float)(m_string.count())); // 将文字本身旋转
painter.drawText(QPointF(-10.0, 10.0), QString("%1").arg(m_string[i]));
painter.restore();
}
}
--------------------------------------------------------------------------------------
void WgtText::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
int font_size = 10;
// 设置字符间距
int text_space = 2;
int wh = height();
QFont font;
font.setFamily("Microsoft YaHei");
// 大小
font.setPointSize(font_size);
// 使用字体
painter.setFont(font);
static QString m_string("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
for(int i=0; i<m_string.count(); i++)
{
// 按正弦函数绘制
float tx = (font_size + text_space) * i;
float ty = sin(tx);
//压缩y坐标
ty = wh/2 + ty*(wh/2*0.2);
painter.drawText(QPointF(tx, ty), QString("%1").arg(m_string[i]));
}
return QWidget::paintEvent(event);
}