hello
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
views:
167answers:
2
+2
A:
I'm creating a kind of "Framework" to do this. There are 2 approaches:
- Handle mouse messages, create a QGraphicsLineItem object, add to Scene and modify it during the creation process.
- 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.
Mason Chang
2010-07-21 10:14:53
+1
A:
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.
Narek
2010-07-23 19:57:05