回复: QT下如何绘制等高线图
#6 回 砍猪佩琪 的帖子 [20091001753 11-06 13:45]
砍猪佩琪:请问你的数据是如何与颜色对应的呢,用的是什么类呀 (2019-11-06 09:36)
海拔 与 颜色 的映射关系,实际上是你自己定义的。
当然,你也可以参照上面叫 texturesurface 的例子,里面有一段代码:
int height = 400;
int width = 100;
int border = 10;
QLinearGradient gr(0, 0, 1, height - 2 * border);
gr.setColorAt(1.0f, Qt::black);
gr.setColorAt(0.8f, Qt::darkGreen);
gr.setColorAt(0.6f, Qt::green);
gr.setColorAt(0.4f, Qt::yellow);
gr.setColorAt(0.2f, Qt::red);
gr.setColorAt(0.0f, Qt::darkRed);
QPixmap pm(width, height);
pm.fill(Qt::transparent);
QPainter pmp(&pm);
pmp.setBrush(QBrush(gr));
pmp.setPen(Qt::NoPen);
pmp.drawRect(border, border, 35, height - 2 * border);
pmp.setPen(Qt::black);
int step = (height - 2 * border) / 5;
for (int i = 0; i < 6; i++) {
int yPos = i * step + border;
pmp.drawLine(border, yPos, 55, yPos);
pmp.drawText(60, yPos + 2, QString("%1 m").arg(550 - (i * 110)));
}
这段代码生成的 QPixmap 即:
#7 [alone_work 11-06 14:12]
#8 回 20091001753 的帖子 [砍猪佩琪 11-06 17:11]
20091001753:海拔 与 颜色 的映射关系,实际上是你自己定义的。
当然,你也可以参照上面叫 texturesurface 的例子,里面有一段代码:
int height = 400;
....... (2019-11-06 13:45)
非常感谢!!
#9 [沉默小ai 11-06 23:03]
学到不少,感觉QT博大精深