如何使用QT图形视图进行绘图

发布于 2024-09-10 22:18:51 字数 93 浏览 2 评论 0原文

我正在尝试使用QT的图形视图来画线 可以在场景中绘制多个对象,但是否可以在 Qt 场景内进行(实时线条)绘制,以及如何绘制?
示例代码将不胜感激
提前致谢

im trying to use the graphic veiw of QT to draw lines
it's possible to draw a multiple objects in the scene but is it possible to do a (real time lines ) drawing inside the Qt scene , and how ?
a sample code would be highly appreciated
thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

何处潇湘 2024-09-17 22:18:51

我正在创建一种“框架”来做到这一点。有两种方法:

  1. 处理鼠标消息,创建 QGraphicsLineItem 对象,添加到场景并在创建过程中对其进行修改。
  2. 派生QGraphicsScene,创建一个QGraphicsLineItem但不添加到场景中,在drawForeground时绘制它,创建完成后将其添加到场景中。

由于QGraphicsScene默认会在BSP树中索引对象,并且频繁更改项目时会影响性能,因此在创建时使用第二种方法可以获得更高的性能,但需要更多的代码工作。

I'm creating a kind of "Framework" to do this. There are 2 approaches:

  1. Handle mouse messages, create a QGraphicsLineItem object, add to Scene and modify it during the creation process.
  2. Derive QGraphicsScene, create a QGraphicsLineItem but NOT added to scene, draw it when drawForeground, added it to scene after finished the creation.

Because QGraphicsScene will index objects in a BSP tree by default, and it will impact the performance when changing items frequently, you can get higher performance when using the 2nd approach during creation, but more code work.

以酷 2024-09-17 22:18:51

1) 创建 GraphicsView 和场景

m_graphScen = new QGraphicsScene;
m_graphScen->setSceneRect(0,0,790,290);

m_graphView = new QGraphicsView;
m_graphView->setFixedSize(800, 300);
m_graphView->setScene(m_graphScen);

2) 创建一个通过处理鼠标事件执行以下操作的插槽:

m_graphScen->addLine(0, 250, 700, 250, QPen(QBrush(Qt::black),1));
m_graphView->show();

此外,如果您需要编写或绘制文本,请参阅 此处

1) Create GraphicsView and Scene

m_graphScen = new QGraphicsScene;
m_graphScen->setSceneRect(0,0,790,290);

m_graphView = new QGraphicsView;
m_graphView->setFixedSize(800, 300);
m_graphView->setScene(m_graphScen);

2) Create a slot which is doing the following by handling the mouse events:

m_graphScen->addLine(0, 250, 700, 250, QPen(QBrush(Qt::black),1));
m_graphView->show();

Also if you need to write or draw text see here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文