2010-07-21 70 views

回答

5

我创建了一种“框架”要做到这一点
感谢。有2种方法:

  1. 手柄鼠标消息,创建一个对象QGraphicsLineItem,添加到场景,并在创建过程中修改。
  2. 导出QGraphicsScene,创建一个QGraphicsLineItem但不添加到场景中,绘制drawForeground时,在完成创建后将其添加到场景中。

因为QGraphicsScene会在默认情况下,BSP树索引对象,并改变项目时频繁,你可以创建过程中使用第二方法时获得更高的性能会影响性能,但更多的代码工作。

2

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(); 

此外,如果你需要写或画文见here