0

I have a Qt Location map upon which I'd like to draw some polygons. The MapPolygon class provides an easy way to drape a polygon over the terrain, as desired. I would like to shade the polygon using a gradient, like RadialGradient.

I'm playing with the Map Viewer example application in Qt 5.9. I edited the map/MapComponent.qml QML file and added the following item to the map:

MapCircle {
    center {
        latitude: -27.5
        longitude: 153.0
    }
    radius: 5000.0
    border.width: 0
    RadialGradient {
            anchors.fill: parent
            gradient: Gradient {
                GradientStop { position: 0.0; color: "red" }
                GradientStop { position: 0.25; color: "red" }
                GradientStop { position: 0.5; color: Qt.rgba(0, 0, 0, 0) }
            }
        }
}

The documentation for MapCircle indicates that it uses MapPolygon under the hood, so I'm using it here for simplicity. If I run the test application, the gradient seems to work:

enter image description here

This is what I would like. However, if I scroll the viewport so that part of the circle is clipped out of the viewable area, the gradient doesn't look right:

enter image description here

Here's what appears to be happening to me:

  • When the circle is clipped partially offscreen, it adjusts its bounding box to reflect the portion of the screen that it covers.

  • Since the gradient is anchored to the parent MapCircle object, it automatically stretches its size to cover the clipped bounding box.

  • This results in the entire radial gradient shape being rendered in the compressed bounding box, which is not what I want. I want the gradient object's geometry to stay attached to the circle's true size and location. Instead of the compressed gradient that I see in the second picture, I want to see a similarly-clipped portion of the original radial gradient.

Is this possible with Qt 5.9? It's not clear to me whether this is a rendering bug, or if it's just not intended to be usable this way.

Jason R
  • 11,159
  • 6
  • 50
  • 81
  • You are asking 2 questions here: 1) is that a bug? yes, that's a bug, most likely it will be fixed in the next patch version 2) will it work with QGeoPolygon? most likely not like you want it to work. In general what would you expect here? – Pa_ Jul 27 '17 at 15:49
  • @Paul I thought I illustrated it in the OP. I would like the gradient to stay anchored to the polygon, so that if I scroll a portion of it out of the viewport, it doesn't squash the gradient to cover only the visible region. Instead, a portion of the gradient would be clipped offscreen. – Jason R Jul 28 '17 at 22:41
  • right, but the gradient will be radial and the polygon is, well, a polygon. Assuming that 1 will be fixed, i'm still unsure of what is the use case where combining a polygon with a radial gradient will look like something usable. Unless your polygons are almost round, i mean. – Pa_ Jul 29 '17 at 21:37
  • I see your point. Radial gradients do fit best with circles (or portions of a circle, a la QPainter::drawPie()). But if gradients did work, linear and/or conical gradients would be applicable to other polygon types as well. With more general polygon types, you would want some control about where the origin of the gradient is anchored on the polygon. – Jason R Jul 29 '17 at 22:06

0 Answers0