Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Transparency of overlapping polygons in Qt
Qt 6.11 is out! See what's new in the release blog

Transparency of overlapping polygons in Qt

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Borkr
    wrote on last edited by
    #1

    Is there an easy way to make an overlapping area between two polygons transparent? Preferably built-in functions within the Qt widgets/Qt 2D graphics C++ framework. (not QML)

    I'm rendering map data extracted from Openstreetmap.org and some advanced relations between ways (line segments) are given as inner and outer ways that form polygons.

    For example, a lake can have outer ways that form the polygon, and several inner ways that form islands within the lake.

    I am able to correctly build the outer polygons and inner polygons separately but I struggle to find an easy way to make the area that overlaps with inner polygons transparent.

    In the image below the white areas are separate polygons drawn with white, that's the area that I'd like to make transparent.

    White should be transparent area of blue

    I tried to use QPainterPath for the outer polygons and call

    QPainterPath QPainterPath::subtracted(const QPainterPath &inner) const
    

    but the result was a blank screen.

    Do I have to create new polygons myself prior to rendering?

    Should the QPainterPath solution work and I messed something up?

    Is there some magic that can be done using QPen/QBrush to paint overlapping areas transparent?

    Any tips on how to approach this is highly appreciated.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Borkr
      wrote on last edited by
      #2

      It seems I messed up the QPainterPath-approach. It works now.

      I got it working with QPolygonF directly, as it has a subtracted() method similar to QPainterPath. However, the implementation of subtracted in QPolygonF left artifacts as lines between start vertex of every inner polygon to the start vertex of the outter polygon.

      Using QPainterPath::addPolygon and performing the subtraction worked flawlessly.

      Intended result

      Ref.
      https://bugreports.qt.io/browse/QTBUG-53720
      http://www.qtcentre.org/threads/19463-Draw-polygon-with-holes

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved