DRAWTEXT(CROSS(DIF,DEA),LOW*0.97, '△'),COLORYELLOW,LINETHICK3,ALIGN0; 也不行
时间: 2023-09-13 12:10:17 浏览: 56
DRAWTEXT 函数的用法是 DRAWTEXT(string, x, y)。根据你提供的代码,DRAWTEXT 函数的参数中缺少一个 string 参数,因此会报错。你需要将代码修改为:
DRAWTEXT('△', CROSS(DIF, DEA), LOW * 0.97), COLORYELLOW, LINETHICK3, ALIGN0;
这样就可以正常绘制文本了。另外,需要注意的是,DRAWTEXT 函数的参数中的 x 和 y 坐标是以像素为单位的,因此需要根据实际情况进行调整,以确保文本显示在正确的位置。
相关问题
通达信指标,这段报错 DRAWTEXT(CROSS(DIF,DEA),LOW*0.97, '△'),COLORYELLOW,LINETHICK3,ALIGN1; 不能使用ALIGN1是怎么回事
通达信中的 ALIGN 函数是一种辅助指标,用于将某个指标的数值对齐到另一个指标的数值上。ALIGN 函数有两种用法,即 ALIGN0 和 ALIGN1,其中 ALIGN1 是对齐指标的最后一个值,ALIGN0 是对齐指标的第一个值。
在你提供的代码中,使用了 ALIGN1,但是 DRAWTEXT 函数不支持 ALIGN1 参数,只支持 ALIGN0 参数。因此,你可以将代码中的 ALIGN1 改为 ALIGN0,即将代码修改为:
DRAWTEXT(CROSS(DIF,DEA),LOW*0.97, '△'),COLORYELLOW,LINETHICK3,ALIGN0;
这样就可以正常使用 ALIGN 函数了。
修改绘制刻度所对应的字体让它绕平面圆形排列 void QDiscWidget::draw_disc_text(QPainter &p) { p.save(); QString text; QPen pen(QColor(255, 255, 255)); pen.setWidth(0.5); p.setPen(pen); QFont font("Microsoft YaHei", 3); p.setFont(font); int pointsize = font.pointSize(); int radius = 100; float width = pointsize * 3; float height = pointsize * 2; for(int i = 0; i < 12; ++i) { double y = -(double)radius * 0.97 * qCos(i * M_PI/ 6.0) -1.5; double x = -(double)radius * 0.97 * qSin(i * M_PI / 6.0) -2.5; if (i == 0) { text = "0"; } else { text = text.sprintf("%d", (360 - 30 * i)); } p.drawText(QRectF(x, y, width, height), Qt::AlignCenter, text); } p.restore(); }
可以使用 QPainter 的 rotate() 函数实现绘制刻度所对应的字体绕平面圆形排列。具体方法如下:
1. 将绘制原点移动至圆心处,即添加以下代码:
```
p.translate(QPointF(0, 0));
```
2. 在 for 循环中绘制每个刻度时,旋转 QPainter,使其与刻度对应的位置对齐。具体代码如下:
```
p.rotate(-30 * i);
```
3. 将绘制完一个刻度后的 QPainter 旋转回原来的位置。具体代码如下:
```
p.rotate(30 * i);
```
修改后的函数如下:
```
void QDiscWidget::draw_disc_text(QPainter &p) {
p.save();
QString text;
QPen pen(QColor(255, 255, 255));
pen.setWidth(0.5);
p.setPen(pen);
QFont font("Microsoft YaHei", 3);
p.setFont(font);
int pointsize = font.pointSize();
int radius = 100;
float width = pointsize * 3;
float height = pointsize * 2;
p.translate(QPointF(0, 0)); // 将绘制原点移动至圆心处
for(int i = 0; i < 12; ++i) {
double y = -(double)radius * 0.97 * qCos(i * M_PI/ 6.0) -1.5;
double x = -(double)radius * 0.97 * qSin(i * M_PI / 6.0) -2.5;
if (i == 0) {
text = "0";
} else {
text = text.sprintf("%d", (360 - 30 * i));
}
p.rotate(-30 * i); // 旋转 QPainter
p.drawText(QRectF(x, y, width, height), Qt::AlignCenter, text);
p.rotate(30 * i); // 旋转回原来的位置
}
p.restore();
}
```