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. QPainterPath with variable line width
Forum Updated to NodeBB v4.3 + New Features

QPainterPath with variable line width

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 5.9k Views 1 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I have a QPainterPath that I need to draw in a QWidget.

    My actual code is:
    @
    void MyWidget::paintEvent(QPaintEvent *e)
    {
    QPainter painter(this);
    painter.drawPath(m_path);
    }
    @

    This way I get a line with constant line width. Is there a way to draw the line with a width value per point?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You need to draw points individually/separately. When you are drawing you need to set the appropriate width of pen.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • L Offline
        L Offline
        luca
        wrote on last edited by
        #3

        [quote author="Dheerendra" date="1406217904"]You need to draw points individually/separately. When you are drawing you need to set the appropriate width of pen. [/quote]

        But I need a continuous line...

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Just to be sure I'm understanding you right, you would like each point of your path to have a different width ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luca
            wrote on last edited by
            #5

            Hi,
            yes, suppose you have a touchscreen and you want to draw a path with a pen width depending on you Stylus pressure.

            I have a series of X,Y and pressure (an integer from 0 to 500).

            I want a line very similar on what happens in real word where if you press more in the paper you got a stronger line.

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              Got it. You draw point everytime with setting penWidth. This is the only way.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • L Offline
                L Offline
                luca
                wrote on last edited by
                #7

                [quote author="Dheerendra" date="1406257334"]Got it. You draw point everytime with setting penWidth. This is the only way.[/quote]

                Thanks but it isn't what I need.
                If I move the pointer in the touchscreen very fast I get some space between consecutive points so I haven't a "line".

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

                  LineWidth is probably not a solution for what you need.
                  In effect, you need to draw polygons, not lines. That way, you have full control on how wide they are in each segment. You can even create "lines" that start wide at one end, and become narrow at the other end, and so forth.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    luca
                    wrote on last edited by
                    #9

                    Thanks,
                    now I'm trying with drawLine or drawPolyline but I can't find how to set variable line width...
                    You told me this:
                    [quote]
                    You can even create "lines" that start wide at one end, and become narrow at the other end
                    [/quote]
                    Are you sure it's possible?

                    Thanks

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

                      Yes, you draw a polygon that's wide at one end, and narrow at the other. It's just a matter of the point coordinates to get the effect you want.

                      Something like this:
                      @QPolygonF polygon;
                      polygon << QPointF(0.0, 0.0) << QPointF(100.0, 3.0) << QPointF(100.0, 6.0) << QPointF(0.0, 9.0);@

                      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