我爲我的應用程序創建了氣球蒙件。問題是小部件的尖端是鋸齒狀的,所以我做錯了什麼?Qt氣球部件蒙版
void BalloonWidget::paintEvent(QPaintEvent *)
{
QVector<QPointF> vertices;
vertices << QPointF(0, 0)
<< QPointF(width(), 0)
<< QPointF(width(), height() * 0.8)
<< QPointF(width() * 0.60, height() * 0.8)
<< QPointF(width() * 0.5, height())
<< QPointF(width() * 0.40, height() * 0.8)
<< QPointF(0, height() * 0.8);
balloonPoly = QPolygonF(vertices);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::HighQualityAntialiasing, true);
painter.setBrush(QBrush(backgroundColor));
QRegion maskRegion(balloonPoly.toPolygon(), Qt::WindingFill);
painter.drawPolygon(balloonPoly);
setMask(maskRegion);
}
你說得對,鋸齒不是由抗鋸齒造成的,但是默認情況下,QWidget有一個矩形形狀,我必須掩蓋沒有被多邊形覆蓋的區域以獲得自定義形狀。否則,我會在其中繪製一個多邊形的矩形。 – RobRobRob