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. QPainter compositing : how to combine QPainter operations ?

QPainter compositing : how to combine QPainter operations ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 645 Views 2 Watching
  • 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.
  • R Offline
    R Offline
    RedLeg
    wrote on last edited by
    #1

    Hi !

    Is it possible to combine/group multiple QPainter operations so that they are composed (using the defined CompositionMode) at once ?

    I'm asking because with the code/screenshots below (it's python, but the same applies in C++), each piece gets drawn independently, so that there is a dark overlap on pieces with the same color. I'd like the overlap to be visible only on pieces of different colors.

    I search for something like QPainter->startTransaction() ... QPainter->commit(), but couldn't find anything...

    I'm using this in a QGraphicsItem subclass. Using multiple QGraphicItems is not a good workaround, as I'll have a large count of items.

    Many thanks !!!

    Olivier

    def paint(self, painter, option, widget):
        painter.setCompositionMode(QPainter.CompositionMode_Multiply)
        for player in players:
            painter.setPen(player.color)
            # i'd like to group these calls at once
            for piece in player.pieces:
                painter.drawCircle(...)
    

    What I have :
    current.png

    What I want :
    goal.png

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      There's no grouping in painter, but you can group your shapes with QPainterPath. Create one for each color. Set their fill rule to WindingFill, add circles to them and then draw the paths with the painter.

      R 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        There's no grouping in painter, but you can group your shapes with QPainterPath. Create one for each color. Set their fill rule to WindingFill, add circles to them and then draw the paths with the painter.

        R Offline
        R Offline
        RedLeg
        wrote on last edited by
        #3

        Seems to be exactly what I needed for the circles !

        Now, I have the same question for other calls (drawPolyline with a thick dashed round QPen). I guess I'll use your technique with QPainterPathStroker first. I'm just worried it may get a bit heavy computationally as it's a lot of vectors to process. But I'll try first and come back if there's actual perfomance issues !

        @Chris-Kawa Thanks so much for your help !

        1 Reply Last reply
        0
        • gde23G Offline
          gde23G Offline
          gde23
          wrote on last edited by
          #4

          as an alternative you could first paint all the red stuff on a white background without transparency (just use light red).
          Then the same for the blue stuff.
          Finally convert white to alpha and overlay the two images..

          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