我有Tile和生成折线的代码:
bool eventFilter(QObject *obj, QEvent *event) {
if(event->type() == QEvent::Paint) {
QWidget *widget = qobject_cast<QWidget*>(obj);
QBrush brush;
brush.setTexture(QPixmap(":/light.png").scaledToWidth(8, Qt::SmoothTransformation));
brush.setStyle(Qt::TexturePattern);
QPen pen(brush, 8, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
QPainter painter(widget);
painter.setPen(pen);
/* path */
qreal startX = 10.0;
qreal startY = widget->height()/2;
QVector<QPointF> v = {
QPointF(startX + 0 , startY + 0),
QPointF(startX + 25, startY + 20),
QPointF(startX + 50, startY + 30),
QPointF(startX + 75, startY - 10),
QPointF(startX + 100, startY + 10),
QPointF(startX + 125, startY - 20),
QPointF(startX + 150, startY - 5),
QPointF(startX + 175, startY + 15),
QPointF(startX + 200, startY + 0)
};
QPolygonF polygon(v);
painter.drawPolyline(polygon);
}
return QObject::eventFilter(obj, event);
}
执行后我得到这个图像:
但需要得到这样的折线:
如何实施?