這是我試過的,它沒有輸出。我哪裏錯了?如何使用QPainter繪製和填充三角形?
// Start point of bottom line
qreal startPointX1 = 600.0;
qreal startPointY1 = 600.0;
// End point of bottom line
qreal endPointX1 = 600.0;
qreal endPointY1 = 1200.0;
// Start point of top line
qreal startPointX2 = 600.0;
qreal startPointY2 = 600.0;
// End point of top line
qreal endPointX2 = 800.0;
qreal endPointY2 = 1200.0;
QPainterPath path;
// Set pen to this point.
path.moveTo (startPointX1, startPointY1);
// Draw line from pen point to this point.
path.lineTo (endPointX1, endPointY1);
path.moveTo (endPointX1, endPointY1);
path.lineTo (endPointX2, endPointY2);
path.moveTo (endPointX2, endPointY2);
path.lineTo (startPointX1, startPointY1);
painter.setPen (Qt :: NoPen);
painter.fillPath (path, QBrush (QColor ("blue")));
我剛纔想創建這3點之間的路徑,並填補了區域,但沒有顯示輸出。
您是否更改過任何QPainter座標變換矩陣? – Nazar554
@ Nazar554這是我唯一的代碼。除此之外我什麼都沒做。 –