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 drawing lines - configuring line softness (horizontal opacity gradient)

QPainter drawing lines - configuring line softness (horizontal opacity gradient)

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpainterqline
3 Posts 2 Posters 1.7k 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.
  • V Offline
    V Offline
    Vagabond
    wrote on 18 May 2018, 12:00 last edited by
    #1

    Hi all!

    I am looking for a way to apply a horizontal opacity gradient when painting QLine elements using QPainter. Put simply, I want to be able to have the line opacity decrease the further away from the line center it is being painted. The effect I want to achieve corresponds to what a lot of image editing tools comonly describe as hardness of a brush. Here is a sample image that compares a line using a hard brush to a soft one.

    This would be a minimum example for painting a regular QLine:

    QPainter p;
    p.setPen(QPen(Qt::black, 12, Qt::SolidLine, Qt::RoundCap));
    p.drawLine(QPointF(0,0), QPointF(1024,1024));
    

    How and where would I configure the line hardness I am describing? Is there something like a fall-off property when painting QLine elements?

    In the docs I could only find examples for how to apply linear gradients between set points, which is not what I am looking for.

    M 1 Reply Last reply 18 May 2018, 12:53
    0
    • V Vagabond
      18 May 2018, 12:00

      Hi all!

      I am looking for a way to apply a horizontal opacity gradient when painting QLine elements using QPainter. Put simply, I want to be able to have the line opacity decrease the further away from the line center it is being painted. The effect I want to achieve corresponds to what a lot of image editing tools comonly describe as hardness of a brush. Here is a sample image that compares a line using a hard brush to a soft one.

      This would be a minimum example for painting a regular QLine:

      QPainter p;
      p.setPen(QPen(Qt::black, 12, Qt::SolidLine, Qt::RoundCap));
      p.drawLine(QPointF(0,0), QPointF(1024,1024));
      

      How and where would I configure the line hardness I am describing? Is there something like a fall-off property when painting QLine elements?

      In the docs I could only find examples for how to apply linear gradients between set points, which is not what I am looking for.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 18 May 2018, 12:53 last edited by
      #2

      @Vagabond
      Hi
      You can apply QGradient to brush and QPen has ctor that takes a brush
      https://forum.qt.io/topic/77640/is-it-possible-to-set-the-pen-color-to-a-gradient/4

      V 1 Reply Last reply 18 May 2018, 13:40
      0
      • M mrjj
        18 May 2018, 12:53

        @Vagabond
        Hi
        You can apply QGradient to brush and QPen has ctor that takes a brush
        https://forum.qt.io/topic/77640/is-it-possible-to-set-the-pen-color-to-a-gradient/4

        V Offline
        V Offline
        Vagabond
        wrote on 18 May 2018, 13:40 last edited by
        #3

        @mrjj Thanks! I'll look into that. I got another reply from stackoverflow which I will also give a shot. I'll keep everyone in both forums posted as soon as I have some results.

        1 Reply Last reply
        1

        1/3

        18 May 2018, 12:00

        • Login

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