Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QPainterPath to draw curve with fading
QtWS25 Last Chance

QPainterPath to draw curve with fading

Scheduled Pinned Locked Moved Unsolved Game Development
5 Posts 3 Posters 801 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.
  • E Offline
    E Offline
    Ejok88
    wrote on 27 Jan 2023, 13:17 last edited by Ejok88
    #1

    I want to draw an arbitrary curve (by points). I was able to do this with QPainterPath, but this tool only allows drawing with a solid pen, but I need to draw a curve with fading edges (channel apha = 1 in the center of the curve and alpha = 0 at the edges of the curve).

    This picture as an example of the expected result (red curve):

    photo_2021-11-15_18-41-34.jpg

    I know that QPainter depends on QPen class, but I didn't find any method how to tune QPen to draw in a custom style.

    #QPainter #QPainterPath

    1 Reply Last reply
    0
    • J Offline
      J Offline
      johngod
      wrote on 29 Jan 2023, 16:42 last edited by
      #2

      AFAIK QPainter is not suitable to do that kind of lines. Take a look at this discussion, there are some hacks, but ... https://stackoverflow.com/questions/59591826/draw-a-line-and-curves-with-fading-edges-with-qpainter.
      I think the proper way would be to use OpenGL ou Quick3D, or other low level library and make your own shaders. I have done something like that in Opengl, but it was just a just a fuzzy circle, check here. For lines, it should be the same concept, the proper way is to use a mix() function to mix the vertex colors in fragment shader as they "fade" way from the line. Using shaders is not trivial at all, sorry if this is not the answer you're looking for, but I just dont know a easy way to do that in QPainter, I think it is not the right tool for what you want to achieve.

      E 1 Reply Last reply 25 Jan 2025, 14:40
      3
      • J johngod
        29 Jan 2023, 16:42

        AFAIK QPainter is not suitable to do that kind of lines. Take a look at this discussion, there are some hacks, but ... https://stackoverflow.com/questions/59591826/draw-a-line-and-curves-with-fading-edges-with-qpainter.
        I think the proper way would be to use OpenGL ou Quick3D, or other low level library and make your own shaders. I have done something like that in Opengl, but it was just a just a fuzzy circle, check here. For lines, it should be the same concept, the proper way is to use a mix() function to mix the vertex colors in fragment shader as they "fade" way from the line. Using shaders is not trivial at all, sorry if this is not the answer you're looking for, but I just dont know a easy way to do that in QPainter, I think it is not the right tool for what you want to achieve.

        E Offline
        E Offline
        Ejok88
        wrote on 25 Jan 2025, 14:40 last edited by Ejok88
        #3

        @johngod Thanks for the help, sorry for the late reply.. I'm coming back to this problem and I want to try to do something with OpenGL. Do you have any new thoughts about this problem? What tutorial did you use to create the pointed git repository?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bondrusiek
          wrote on 26 Jan 2025, 11:50 last edited by
          #4

          @Ejok88 Hi,
          you can see official Qt examples: https://doc.qt.io/qt-6/examples-widgets-opengl.html. Additionally, you can review the chapter of the free book Qt6 QML Book and see the chapter on shaders. I can recommend my repository where I use OpenGL: https://github.com/Przemekkkth/camera-opengl-qt.

          1 Reply Last reply
          1
          • J Offline
            J Offline
            johngod
            wrote on 5 Feb 2025, 10:28 last edited by
            #5

            @Ejok88 Hi
            I used the the book of shaders site tutorials to create the fuzzy circle check here https://thebookofshaders.com/
            I actually got a very simple idea for your problem, just use a line with width which is just nothing more that a rectangle with two colors on the edjes, and use GL_TRIANGLE_STRIP , see this new example https://bitbucket.org/joaodeusmorgado/opengltutorials/src/master/T11_FuzzyLine/mygl.cpp#lines-185
            Then you just add vertices to compose your line, note that you have to use "two" lines side by side to make the double fade out effect. Then you need to add 3 more lines without width, to the center and the 2 lines in the extremes. A bit of work but doable. I can help further if you need, but right now I just to much work overloaded. What is your use case, are you using widgets and Opengl ? I think going with quick3d would be easier, it that is an option for you.

            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