0

I need to increase the pen width for the below code using Painter/QPen, but nothing that I try works. Can someone please point me in the right direction?

    while c_len < MAX_LENGTH:
        # Set the pen color for this segment
        sat = 200 * (MAX_LENGTH - c_len) / MAX_LENGTH
        hue = (color + 130 * (height - y_s) / height) % 360
        p.setPen(QPen(QColor_HSV(hue, sat, 255, 20), 2))
martineau
  • 119,623
  • 25
  • 170
  • 301
Brian
  • 53
  • 1
  • 5
  • You're not increasing *anything*. Not only the `c_len` is not used for the pen, but you are not even *actually* increasing its value. – musicamante Mar 28 '22 at 08:24
  • I realize that. All of my attempts at increasing the width have failed... so I didn't even out that part in. – Brian Mar 28 '22 at 19:28
  • 1
    If we can't see those attempts, how can we help you? We cannot tell you what is wrong with your code if you don't show us what you did. – musicamante Mar 28 '22 at 19:37

1 Answers1

0

You can use the setWidth method of QPen like so:

while c_len < MAX_LENGTH:
    # Set the pen color for this segment
    sat = 200 * (MAX_LENGTH - c_len) / MAX_LENGTH
    hue = (color + 130 * (height - y_s) / height) % 360
    pen = QPen(QColor_HSV(hue, sat, 255, 20))
    pen.setWidth(2)
    p.setPen(pen)

Just giving the value 2 to the constructor does not work, because there is no matching signature for your arguments.

As an alternative, use arguments that are supported by the signature:

pen = QPen(QColor_HSV(hue, sat, 255, 20), 2, QtCore.Qt.SolidLine)

This is preferred, as it avoids a separate function call which is slow in Python.

MiaPlan.de
  • 102
  • 8