Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt drawPolygon with Qt::NoBrush, still being filled....
Qt 6.12 LTS is out! See what's new in the release blog

Qt drawPolygon with Qt::NoBrush, still being filled....

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.4k 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.
  • S Offline
    S Offline
    SimonPlatten
    wrote on last edited by SimonPlatten
    #1

    I'm using Qt 5.9.1, I am drawing two polygon's one on top of the other with a pen with Qt::NoBrush, but the interior is still being filled in, semi opaque but filled....why?

    Pen pnOutline;
    pnOutline.setBrush(Qt::NoBrush);
    pnOutline.setColor(clrBorder);
    pnOutline.setWidth(3);
    pobjPainter->setPen(pnOutline);
    pobjPainter->drawPolygon(plyBorder, sizeof(plyBorder) / sizeof(plyBorder[0]));
    pnOutline.setColor(clrOutline);
    pnOutline.setWidth(2);
    pobjPainter->setPen(pnOutline);  //Edit, missed this in the original post...but it is there!
    pobjPainter->drawPolygon(plyOutline, sizeof(plyOutline) / sizeof(plyOutline[0]));
    

    What I get from this is the first polygon draw with a thick black outline and no filling, then the white polygon draw on top but with a semi-opaque filled interior.

    raven-worxR 1 Reply Last reply
    0
    • S SimonPlatten

      I'm using Qt 5.9.1, I am drawing two polygon's one on top of the other with a pen with Qt::NoBrush, but the interior is still being filled in, semi opaque but filled....why?

      Pen pnOutline;
      pnOutline.setBrush(Qt::NoBrush);
      pnOutline.setColor(clrBorder);
      pnOutline.setWidth(3);
      pobjPainter->setPen(pnOutline);
      pobjPainter->drawPolygon(plyBorder, sizeof(plyBorder) / sizeof(plyBorder[0]));
      pnOutline.setColor(clrOutline);
      pnOutline.setWidth(2);
      pobjPainter->setPen(pnOutline);  //Edit, missed this in the original post...but it is there!
      pobjPainter->drawPolygon(plyOutline, sizeof(plyOutline) / sizeof(plyOutline[0]));
      

      What I get from this is the first polygon draw with a thick black outline and no filling, then the white polygon draw on top but with a semi-opaque filled interior.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @SimonPlatten said in Qt drawPolygon with Qt::NoBrush, still being filled....:

      pnOutline.setColor(clrOutline);
      pnOutline.setWidth(2);
      pobjPainter->drawPolygon(plyOutline, sizeof(plyOutline) / sizeof(plyOutline[0]));

      because you just assign the new values to the pen object.
      But the painter still has a copy of the old pen object.
      So simply also reassign the pen to the painter, whenever you update properties of the pen.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • S Offline
        S Offline
        SimonPlatten
        wrote on last edited by
        #3

        Sorry, in the original the SetPen is there, unfortunately due to issues with the company firewall and blocking forums, I had to type it all in again, instead of simply cutting and pasting.

        But evening if it was missing, this wouldn't explain why the contents of the polygon appear to be filled?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by Asperamanca
          #4

          All you set is the pen's brush. This is only used to fill strokes of the pen.
          The painter has it's own brush, which you have to set.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SimonPlatten
            wrote on last edited by
            #5

            Thank you, thats fixed it, why does a painter have a brush when the pen also has a brush ?

            I would have thought that setting the pen brush would set the painter...obviously wrong.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Asperamanca
              wrote on last edited by
              #6

              Let's say you want to draw a polygon filled red, with a wide outline filled in a gradient - black on the left turning to green on the right.
              In that case you would assign a gradient brush to the pen to achieve the gradient effect, and a red brush to the painter directly to achieve the polygon fill effect.

              1 Reply Last reply
              1

              • Login

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