Reputation: 3722
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
Upvotes: 3
Views: 12750
Reputation: 3459
I'm creating a kind of "Framework" to do this. There are 2 approaches:
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.
Upvotes: 5
Reputation: 39881
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.
Upvotes: 2