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:
thanks!
-
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.
-
The usual is:
- Update value
- 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:
https://stackoverflow.com/questions/40877791/pyqt5-update-mainwindow-after-paintevent
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!
-
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 :)