如何在 MapPolyline 中绘制虚线?

时间:2020-12-23 09:42:39

标签: c++ qt qml qt5

如何在 MapPolyline 中绘制虚线?将 LineItem 中的属性设置为 style: Qt.DashStyle 无效。

MapPolyline {
        id: nearestMapPolyline
        z: m_mapPolygon.z
        visible: nearestMapPolyline.visible
        smooth: true
        antialiasing: true
        line.color: m_mapPolyline.lineColor
        line.width: m_mapPolyline.lineWidth
        onPathChanged: {
            nearestDataModel.clear();

            for (var i = 0; i < nearestMapPolyline.path.length - 1; ++i) {
                nearestDataModel.append({ "p1": i, "p2": i + 1});
            }
        }
        ListModel {
            id: nearestDataModel
        }
        Instantiator {
            model: nearestDataModel
            delegate: MapItemGroup {
                Anchor {
                    id: nearestPoint1
                    coordinate: nearestMapPolyline.path[p1]
                }
                Anchor {
                    id: nearestPoint2
                    coordinate:  nearestMapPolyline.path[p2]
                }
                LineItem {
                    opacity: 1
                    color: m_mapPolyline.lineColor
                    lineWidth: m_mapPolyline.lineWidth
                    style: Qt.DashLine
                    frontier: m_mapPolyline.frontier
                    visible: m_mapPolygon.visible
                    x1: nearestPoint1.x
                    y1: nearestPoint1.y
                    x2: nearestPoint2.x
                    y2: nearestPoint2.y
                    z: nearestMapPolyline.z

                    MouseArea {
                        anchors.fill: parent
                        cursorShape: active ? Qt.PointingHandCursor : Qt.ArrowCursor
                    }
                }
            }
            onObjectAdded: map.addMapItemGroup(object)
            onObjectRemoved: map.removeMapItemGroup(object)
        }

        function clearPath() {
            nearestMapPolyline.path = []
        }
    }

附言我使用 MapPolyline 是因为我们的项目在捆绑 MapPolyline 中使用 MapPolygon。 也许 smbd 知道这个问题?以及如何修复它。

P.p.s.在 C++ 样式中 LineItem 看起来像

void LineItem::setDashPattern(const QVector<qreal> &pattern) noexcept 
{
#ifndef USE_QPAINTER
if (_dashPattern == pattern)
    return;
_dashPattern = pattern;
setStyle(Qt::CustomDashLine);
#else
if (_pen.dashPattern() == pattern)
    return;
_pen.setDashPattern(pattern);
emit styleChanged(_pen.style());
#endif
emit dashPatternChanged(pattern);
update();
}

0 个答案:

没有答案
相关问题