5 c++ plot qt qt-creator
我正在使用QT在C++中编写一个应用程序,你有n个点并计算它的凸包.但是,一旦计算出来,我就不知道如何绘制点并绘制船体的边界.制作菜单按钮等很简单,但我不确定我知道这样做的工具.
你怎么做到这一点?
phy*_*att 11
addEllipseQGraphicsView2D绘图非常好,并为您提供了许多显示它的选项.它不像为绘制科学数据那样量身定制qwt,而只是为了展示一堆点,几何或动画以及其他很多东西.请参阅Qt的Graphics View Framework文档和示例.
这是你如何在a中绘制一堆点并在a中QGraphicsScene显示它QGraphicsView.
#include <QtGui/QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QPointF>
#include <QVector>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QVector <QPointF> points;
// Fill in points with n number of points
for(int i = 0; i< 100; i++)
points.append(QPointF(i*5, i*5));
// Create a view, put a scene in it and add tiny circles
// in the scene
QGraphicsView * view = new QGraphicsView();
QGraphicsScene * scene = new QGraphicsScene();
view->setScene(scene);
for(int i = 0; i< points.size(); i++)
scene->addEllipse(points[i].x(), points[i].y(), 1, 1);
// Show the view
view->show();
// or add the view to the layout inside another widget
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
注意:您可能希望调用setSceneRect视图,否则场景将自动居中.请阅读说明QGraphicsScene,并QGraphicsView在Qt文档.你可以缩放视图以显示更多或更少的场景,它可以放入滚动条.我回答了一个相关的问题,在那里我展示了你可以用QGraphicsView你想看的东西做的更多.
您可以创建一个自定义类,从QWidget您重写void paintEvent(QPaintEvent* event)方法的位置派生.在你把积分转换为某种点列表,无论是std::vector<QPoint>或QList<QPoint>然后用折线方法绘制它.例如:
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()));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18251 次 |
| 最近记录: |