1 Attachment(s)
QGraphicsLineItem - selection style
hi,
i draw a line in QGraphicsScene, which can be selected and moved.
Code:
MainPlot->setSceneRect(0,0,500,500);
_Pen.setColor(Qt::red);
_Pen.setWidth(3);
_Line->setPen(_Pen);
_Line->setVisible(true);
MainPlot->addItem(_Line);
ui.view->setScene(MainPlot);
//ui.view is raphicsView
But i don't want that when line is selected, a rectangular is drawn (and line is its diagonal). I want line selection like in "diagramscene" example supplied with Qt documantation (thin rectangular paralel with line), or some custom selection style. How to do that? I can't find this in diagramscene source.
Thanx
Re: QGraphicsLineItem - selection style
Well, you are using QGraphicsLIneItem, while in the Diagram scene example, they are using QGraphicsPolygonItem for arrows.
Read the code for that example :)
Re: QGraphicsLineItem - selection style
Quote:
Originally Posted by
aamer4yu
Well, you are using QGraphicsLIneItem, while in the Diagram scene example, they are using QGraphicsPolygonItem for arrows.
Read the code for that example :)
yes, but Arrow object consists from a line and arrow. It looks like arrow is just drawn in paint method. Arrow class inherits QGraphicsLIneItemwhy is selection different then in basic QGraphicsLIneItem?
what am I missing?
Re: QGraphicsLineItem - selection style
In the diagram escen example they reimplement the boundingRect function .
I think by default it draws the boundingRect with a dotted line .I have checked the QGraphicsLineItem::boundingrect function ,I dont know what does it do ,but ini some cases it returns that rectangle that is in the picture .
Re: QGraphicsLineItem - selection style
I found a solution. It seems that paint method handles "selection display style". so it's easy to set a custom selection style to QGraphicsItem or derivatives.
Code:
{
qint32 _x1=line().x1();
qint32 _y1=line().y1();
qint32 _x2=line().x2();
qint32 _y2=line().y2();
_Pen.setColor(Qt::red);
if (isSelected()) _Pen.setWidth(3);
else _Pen.setWidth(1);
painter->setPen(_Pen);
painter->drawLine(_Line);
if (isSelected())
{
//Draw whatever you want ;)
//painter->drawRect(...)
//painter->drawEllipse(...)
}
}
Re: QGraphicsLineItem - selection style
Hi,
Can you please help me with QGraphicsLineItem paint() function:
I set the pen width to 1 but the line has a width grater the 1 pixel.
Do I have to change other settings?
Thanks