新しいクラスで GraphicsItem を作成し、ポリゴンを描画しましたが、クラスの boundingRect() 内に描画される代わりに、座標でメイン GraphicsView に描画されます。boundingRect( )。
Detector::Detector()
{
Pressed = false; //Initally the pressed boolean is false, it is not pressed
setFlag(ItemIsMovable);
}
QRectF Detector::boundingRect() const
{
return QRectF(780,425,70,40);
}
void Detector::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
QRectF ItemBoundary = boundingRect();
QBrush *fillBrush = new QBrush(QColor(83,71,65));
QPolygon DetectorPolygon;
DetectorPolygon << QPoint(0,0);
DetectorPolygon << QPoint(20,10);
DetectorPolygon << QPoint(70,10);
DetectorPolygon << QPoint(70,20);
DetectorPolygon << QPoint(20,20);
DetectorPolygon << QPoint(0,40);
QPen borderPen;
borderPen.setWidth(2);
borderPen.setColor(QColor(152,133,117));
painter->setBrush(*fillBrush);
painter->setPen(borderPen);
painter->drawPolygon(DetectorPolygon);
// painter->fillRect(ItemBoundary,*fillBrush);
// painter->drawRect(ItemBoundary);
}
コメントアウトされていない最後の 2 行は、boundingRect() を四角形で埋め、上の多角形とは異なり、ItemBoundary 変数をそれに渡すことができます。
ItemBoundary (=BoundingRect()) をポリゴンにも渡すにはどうすればよいですか?
編集: 基本的に、メインのユーザー インターフェイスで QGraphicsView に送信するために、移動して別のクラスとしてポリゴンを描画したいと考えています。