I still keep on failing with this task...
In the constructor of the scene I've placed 2 lines
pen.setWidth(2);
pen.setColor(Qt::black);
line->setPen(pen);
addItem(line);
addItem(line);
QGraphicsLineItem* line = new QGraphicsLineItem(0,0,400,0);
QPen pen(Qt::SolidLine);
pen.setWidth(2);
pen.setColor(Qt::black);
line->setPen(pen);
addItem(line);
line = new QGraphicsLineItem(0,0,0,400);
addItem(line);
To copy to clipboard, switch view to plain text mode
they'll be axises. Also i track mouse coordinates
QPoint p
= mouseEvent
->scenePos
().
toPoint();
QMainWindow* parent
= qobject_cast<QMainWindow
*>
(view
->parentWidget
());
parent
->statusBar
()->showMessage
(QString::number(p.
x())+" ; "+QString::number(p.
y()));
QPoint p = mouseEvent->scenePos().toPoint();
QGraphicsView* view = views()[0];
QMainWindow* parent = qobject_cast<QMainWindow*>(view->parentWidget());
parent->statusBar()->showMessage(QString::number(p.x())+" ; "+QString::number(p.y()));
To copy to clipboard, switch view to plain text mode
why when I just create simple line with dots (10,10) and (60,10) and then call
item->translate(0, 20);
it moves to the position (10,50) and (60,50) ?!
Well, that's not essential for me at this moment...
After hours of mind torturing I've written this:
double x1 = line->line().x1();
double y1 = line->line().y1();
double x2 = line->line().x2();
double y2 = line->line().y2();
double angle = atan((y2 - y1)/(x2 - x1));
{
QTransform tozero;
tozero.translate(-x1/2, -y1/2);
tozero.rotateRadians(angle);
QTransform mirror;
mirror.scale(1, -1);
QTransform back;
back.rotateRadians(-angle);
back.translate(x1/2, y1/2);
item->setTransform(tozero*mirror*back,true);
}
QGraphicsLineItem* line = qgraphicsitem_cast<QGraphicsLineItem*>(curItem);
double x1 = line->line().x1();
double y1 = line->line().y1();
double x2 = line->line().x2();
double y2 = line->line().y2();
double angle = atan((y2 - y1)/(x2 - x1));
foreach (QGraphicsItem* item,group->children())
{
QTransform tozero;
tozero.translate(-x1/2, -y1/2);
tozero.rotateRadians(angle);
QTransform mirror;
mirror.scale(1, -1);
QTransform back;
back.rotateRadians(-angle);
back.translate(x1/2, y1/2);
item->setTransform(tozero*mirror*back,true);
}
To copy to clipboard, switch view to plain text mode
It works perfectly relativly to any line that is paralle to 0x, but if it's not the item flies away =( help me plz!
Bookmarks