你如何在QT中绘制点? [英] How do you plot points in QT?

查看:1441
本文介绍了你如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆