如何使用QT图形视图进行绘图 [英] how to use QT graphic view for drawing

查看:40
本文介绍了如何使用QT图形视图进行绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 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

推荐答案

我正在创建一种框架"来做到这一点.有两种方法:

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

  1. 处理鼠标消息,创建一个 QGraphicsLineItem 对象,添加到场景和在创建过程中对其进行修改.
  2. 派生QGraphicsScene,创建一个QGraphicsLineItem但不添加到场景中,在drawForeground时绘制,创建完成后添加到场景中.
  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.

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

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.

这篇关于如何使用QT图形视图进行绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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