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. change dial cosmetics in python
QtWS25 Last Chance

change dial cosmetics in python

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 8.8k 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.
  • S Offline
    S Offline
    sparrowCE
    wrote on last edited by
    #1

    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:

    0_1525195058793_f7df7012-0013-4d7b-a322-698698009a32-image.png

    or like this:

    0_1525194961859_0513b1c0-5598-4235-a4ec-cd4cd8ca6f24-image.png

    thanks!

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

      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

      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
      • S Offline
        S Offline
        sparrowCE
        wrote on last edited by
        #3

        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.

        JonBJ 1 Reply Last reply
        0
        • S sparrowCE

          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.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @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?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sparrowCE
            wrote on last edited by
            #5

            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:

            0_1525372300677_db319e80-cee0-46f5-94a3-3b3bb8ce46d2-image.png

            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.

            JonBJ 1 Reply Last reply
            0
            • S sparrowCE

              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:

              0_1525372300677_db319e80-cee0-46f5-94a3-3b3bb8ce46d2-image.png

              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.

              JonBJ Online
              JonBJ Online
              JonB
              wrote on last edited by
              #6

              @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.

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

                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.

                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
                1
                • S Offline
                  S Offline
                  sparrowCE
                  wrote on last edited by sparrowCE
                  #8

                  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!

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

                    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 :)

                    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
                    1

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved