QGraphicsEllipseItem
을 사용하면 타원, 원 및 세그먼트/호를 QGraphicsScene
에 추가 할 수 있습니다. 시작과 끝에서 그려진 선이 항상 있다는 것을, 후자는 호를 그리는 데 사용 할 수 있지만 부작용이 -
는
QGraphicsEllipseItem* item = new QGraphicsEllipseItem(x, y, width, height);
item->setStartAngle(startAngle);
item->setSpanAngle(endAngle - startAngle);
scene->addItem(item);
불행하게도, QGraphicsEllipseItem 만 QPainter::drawEllipse()
및 QPainter::drawPie()
지원하십시오 중심에 아크.
실제 원호가 필요한 경우 다음과 같이 할 수 있습니다. 서브 클래스 QGraphicsEllipseItem
와는 paint()
방법 오버라이드 (override) :
class QGraphicsArcItem : public QGraphicsEllipseItem {
public:
QGraphicsArcItem (qreal x, qreal y, qreal width, qreal height, QGraphicsItem * parent = 0) :
QGraphicsEllipseItem(x, y, width, height, parent) {
}
protected:
void paint (QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) {
painter->setPen(pen());
painter->setBrush(brush());
painter->drawArc(rect(), startAngle(), spanAngle());
// if (option->state & QStyle::State_Selected)
// qt_graphicsItem_highlightSelected(this, painter, option);
}
};
그런 다음 여전히 강조 항목을 처리 할 필요가 불행하게도 qt_graphicsItem_highlightSelected
는 Qt는 라이브러리 내부에 정의 된 정적 기능입니다.