你如何在QT中绘制点? [英] How do you plot points in QT?
问题描述
我在C ++中使用QT编写一个应用程序,其中有n个点并计算凸包。但是,一旦计算,我不知道如何绘制点和绘制船体的边框。制作菜单按钮等非常简单,但我不确定我是否知道这样做的工具。
I am writing an application in C++ with QT where you have n points and compute the convex hull of this. However, once this is computed I have no idea how to plot the points and draw the border of the hull. Making menu buttons and such is simple enough, but I'm not sure I know the tools to do this.
如何做?
推荐答案
您可以创建一个自定义类派生自 QWidget
,其中您覆盖 void paintEvent(QPaintEvent * event)
方法。因为你把点放到某种点列表中, std :: vector< QPoint>
或 QList< QPoint>
然后使用Polyline方法绘制它。例如:
You can just create a custom class deriving from QWidget
where you override the void paintEvent(QPaintEvent* event)
method. In that you put the points into some sort of point list, either std::vector<QPoint>
or QList<QPoint>
and then paint it with a Polyline method. For instance:
void Foo::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
std::vector<QPoint> points;
// Fill points with the points
painter.drawPolyLine(points.data(), static_cast<int>(points.size()));
}
这篇关于你如何在QT中绘制点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!