내 QGraphicsItem
을 다시 정의하여 LineString
으로 표시했습니다. 내 자신을 boundingbox
만들고 화가가 추상 메서드를 다시 정의해야하기 때문에 이것을 다시 정의했습니다.Qt의 기울기가있는 라인의 경계선
지금이 코드가 있습니다
QRectF myQGraphicsLine::boundingRect() const
{
double lx = qMin(myLine->getX(0), myLine->getX(1));
double rx = qMax(myLine->getX(0), myLine->getX(1));
double ty = qMin(-myLine->getY(0), -myLine->getY(1));
double by = qMax(-myLine->getY(0), -myLine->getY(1));
return QRectF(lx-size/2,ty, rx -lx + size, by-ty).;
}
void myQGraphicsLine::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
pen.setColor(Qt::red);
QLine line(myLine->getX(0), -myLine->getY(0), myLine->getX(1), -myLine->getY(1));
pen.setWidth(size);
painter->setPen(pen);
painter->setBrush(brush);
painter->drawLine(line);
}
이 모든 작업의 벌금을,하지만 난 boundingRec
에 약간의 문제가 있습니다. 선이 x 축 또는 y 축을 따르는 경우 나는이 결과 얻을 :
를 다른 위치에 나는이 얻을 :
을하고 나는이 필요합니다
boundinRec
을 돌리는 방법을 아는 사람이 있습니까? 고마워요!
체크 아웃 http://doc.qt.io/qt-5/qgraphicsitem.html#boundingRegion – hyde
감사합니다. @hyde, 확인하겠습니다. – Zharios