【发布时间】:2016-09-05 23:32:38
【问题描述】:
我正在尝试在“圆柱体”上绘制文字。这意味着,我有五行文本。顶行按 X 轴旋转 10 度。第二个为5度。中间根本没有旋转。四人行旋转 -5 度。五个旋转 -10 度。 第 1、2、3 行绘制正常,但 4,5 行出现问题。我究竟做错了什么 ? 我提供了一张用于理解问题和代码 sn-p 的图像:
for( int i = 0; i < iterationsCount; ++i )
{
const QRect r( x2, y2, textWidth, itemHeight );
const QString text = sections.at( section ).values.at( index );
int rsc = 0;
p->save();
rsc = widgetHeight / 2 - y;
p->setTransform(QTransform().rotate(rsc, Qt::XAxis));
if( type == Section::DaySectionShort ||
type == Section::DaySectionLong )
{
QStringList values = text.split( QLatin1Char( ' ' ) );
p->setPen(
lighterColor( opt.palette.color( QPalette::WindowText ), 75 ) );
p->drawText( r, Qt::AlignLeft | Qt::TextSingleLine, values.at( 0 ) );
p->setPen( opt.palette.color( QPalette::WindowText ) );
p->drawText( r, Qt::AlignLeft | Qt::TextSingleLine, values.at( 1 ) );
}
else
{
p->drawText( r, Qt::AlignLeft | Qt::TextSingleLine, text );
}
p->setTransform(QTransform().rotate(-rsc, Qt::XAxis));
index = nextIndex( index, sections.at( section ).values.size() );
y += itemHeight + itemTopMargin;
p->restore();
}
【问题讨论】:
-
为什么设置
QTransform().rotate(-rsc...而不使用p?而为什么rsc计算得这么奇怪? -
因为一开始我需要旋转,例如旋转10度。之后我需要将另一个字符串旋转 -10 度,这就是我使用 rsc 和 -rsc 的原因。
-
但是在这个集合和下一个循环迭代之间你什么也没画。你不是在
nextIndex函数里做的吗? -
使用 p->drawText 绘制文本的代码行。查看我底部添加到代码片段的图像的链接。这是一张由这段代码绘制的图像。
标签: c++ qt rotation drawing qpainter