hi friends,
i try using QTransform as
in mainwindow.cpp (GraphicsView())
line1
= new LineItem
(QLineF(2,
4,
132 ,
160), Qt
::blue,
90);
//creating an lineItem in scene line1->setPos(374,215); //settting the line position in screen
scene->addItem(line1);
line1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue, 90); //creating an lineItem in scene
line1->setPos(374,215); //settting the line position in screen
scene->addItem(line1);
To copy to clipboard, switch view to plain text mode
in lineitem.cpp
LineItem
::LineItem(const QLineF &line,
const Qt
::GlobalColor color, qreal angle
) color(color) //constuctor
{
qreal value = angle;
}
LineItem::LineItem(const QLineF &line, const Qt::GlobalColor color, qreal angle)
: QGraphicsLineItem(line),
color(color) //constuctor
{
qreal value = angle;
}
To copy to clipboard, switch view to plain text mode
{
QTransform transform;
painter
->setPen
(QColor(color
));
if(value){
transform.translate(300,300); // here comes the problem
transform.rotate(value);
painter->setTransform(transform);
painter->drawLine(line());
}else{
line().setAngle(value);
painter->drawLine(line());
}
}
void LineItem ::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
QTransform transform;
painter->setPen(QColor(color));
if(value){
transform.translate(300,300); // here comes the problem
transform.rotate(value);
painter->setTransform(transform);
painter->drawLine(line());
}else{
line().setAngle(value);
painter->drawLine(line());
}
}
To copy to clipboard, switch view to plain text mode
in this program if the user send the the angle of rotation the line with the same coordinates i try to rotate ... but without this
transform.translate(x,y); i cant see the line ... more the
line1->setPos(374,215); // graphicasScene
line1->setPos(374,215); // graphicasScene
To copy to clipboard, switch view to plain text mode
this value also not working .. why ? it is defaulter to top left of the screen ...
but if there is no angle argument like
line1
= new LineItem
(QLineF(2,
4,
132 ,
160), Qt
::blue );
//without angle argument
line1 = new LineItem(QLineF(2,4, 132 ,160), Qt::blue ); //without angle argument
To copy to clipboard, switch view to plain text mode
its working fine ... i can setPos() the item ... why? ..
please help
Bookmarks