Important: Please read the Qt Code of Conduct -

change dial cosmetics in python

  • i am using I am using pyqt5 to make a GUI for an experiment setup. i need to convert a dial into a needle to display voltage and current values.
    i've explored mapping an image onto the dial using pixmap and i've looked at subclassing and repainting it. I've tried abandoning the dial and using painter to draw an arc but the arc would not update with the values. I've tried importing a library but could not figure out how to create the new dial without referencing qml.

    i could not find any examples or solutions. i just need a circular gauge like this:


    or like this:



  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Maybe PyQwt will provide you what you want. It's based on Qwt which provides the QwtDial class which looks like it could fit your needs.

    Hope it helps

  • thank you for the suggestion, this is exactly what I was looking for; however, it is no longer maintained and is only supported with old versions of python, pyqt, sip, etc. I am just looking to customize qdial to have an arrow or to be able to repaint drawArc() every time I read in a new value.

  • @sparrowCE
    If you're not going to use, say, PyQwt, then in what way do you intend this to be a question about Python or PyQt? I do not mean this as moaning about your question, just trying to understand what the Python-ness of your question is requesting?

  • my program that interfaces with all of my instruments is written in python. I am using PyQt to create the interface. I am updating qdials by using dial.setValue() then QApplication.processEvents() to update the dial. The dial however looks like this:


    when I need something that looks like a gauge. I would like to subclass it to change the small circle inside.

    ALTERNATIVELY, I have been able to paint an arc using drawArc() to use as a gauge, but when I read in new values from my instruments I don't know how to repaint.

  • @sparrowCE
    OK, I understand. I'm afraid I'm not the person to give you a suggestion (like @SGaist can).

    However, I'm just anticipating that any Qt solution will not involve a PyQt/Python issue.

  • Lifetime Qt Champion

    The usual is:

    1. Update value
    2. Call repaint

    Having to call processEvents to update a control is usually sign of something fishy going on.

  • ik this was a while ago, but i wanted to give the example for repainting that I found helpful:

    and here is the gauge i created:

    minP = 5
    maxP = 6
    rectPrimPPos = [logoPos[0]+logoDim[0]+(arcWidth/2)+2*gaugeSpacer, windowPos[1]] # primary power gauge position [x,y]
    rectPrimPDim = [(rowDim*5/27),(rowDim*5/27)] # primary power gauge dimension [x,y]
    rectPrimP = QtCore.QRect(rectPrimPPos[0],rectPrimPPos[1],rectPrimPDim[0],rectPrimPDim[1]) # rectangle in which to enscribe primary power gauge
    minValPrimP = minP
    maxValPrimP = maxP
    gaugeMaxValPrimP = 180*16 # angle of gauge at max of scale: 180 1/16's degrees
    startAnglePrimP = 0 # primary power gauge: beginning degree of angle
    spanAnglePrimP = int(((vars.primP-minValPrimP)*gaugeMaxValPrimP/(maxValPrimP-minValPrimP))) # primary power gauge: end degree of angle
    qp.setPen(QPen(QColor(40,40,40), arcWidth, Qt.SolidLine)) # set pen for outer arc
    qp.drawArc(rectPrimP, startAnglePrimP, 180*16)  # draw outer arc
    qp.setPen(QPen(QColor(226, 47, 223), arcWidth-5, Qt.SolidLine)) # set pen for inner arc
    qp.drawArc(rectPrimP, startAnglePrimP, spanAnglePrimP) # draw inner arc

    @SGaist: thanks for your advice!

  • Lifetime Qt Champion

    Glad you found something and thanks for sharing !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

Log in to reply