Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Arc gauge
QtWS25 Last Chance

Arc gauge

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
17 Posts 6 Posters 2.9k 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.
  • M Offline
    M Offline
    Mark81
    wrote on 19 Feb 2019, 09:58 last edited by Mark81
    #1

    I kindly request some suggestions how to make a gauge that shows a value using a colored arc.
    There's a background image:
    0_1550570116302_ghiera-stato-OFF.png
    and then I have the colored arc for the inner sectors.
    0_1550570139625_1ph-stato-carica.png
    When value is 0% you will see only the background image. When value is 100% the colored arc will fill all the background one.
    For each intermediate value the colored arc will fill the background one according to the percentage.

    I don't understand how to achieve this.
    Any hint is appreciated!

    R 1 Reply Last reply 19 Feb 2019, 11:46
    0
    • M Mark81
      19 Feb 2019, 09:58

      I kindly request some suggestions how to make a gauge that shows a value using a colored arc.
      There's a background image:
      0_1550570116302_ghiera-stato-OFF.png
      and then I have the colored arc for the inner sectors.
      0_1550570139625_1ph-stato-carica.png
      When value is 0% you will see only the background image. When value is 100% the colored arc will fill all the background one.
      For each intermediate value the colored arc will fill the background one according to the percentage.

      I don't understand how to achieve this.
      Any hint is appreciated!

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 19 Feb 2019, 11:46 last edited by
      #2

      @Mark81
      simply paint ieach section yourself yourself using a Canvas element:

      Canvas {
           onPaint: {
                  var ctx = getContext("2d");
                  ctx.resetTransform()
                  ctx.reset();
      
                 // do the painting on ctx
                 // e.g. ctx.arc( x, y, radius, angleRadStart, angleRadStart, false)
          }
      }
      

      See this example, it's for HTML5 but it's still applicable.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      M 1 Reply Last reply 19 Feb 2019, 12:05
      1
      • R raven-worx
        19 Feb 2019, 11:46

        @Mark81
        simply paint ieach section yourself yourself using a Canvas element:

        Canvas {
             onPaint: {
                    var ctx = getContext("2d");
                    ctx.resetTransform()
                    ctx.reset();
        
                   // do the painting on ctx
                   // e.g. ctx.arc( x, y, radius, angleRadStart, angleRadStart, false)
            }
        }
        

        See this example, it's for HTML5 but it's still applicable.

        M Offline
        M Offline
        Mark81
        wrote on 19 Feb 2019, 12:05 last edited by Mark81
        #3

        @raven-worx I can try it but I see two major issues:

        • it would quite hard to perfectly fit each sector if they are not generated automatically using a function (like I would do with mine)
        • it would work only if the requested painting is easy to reproduce. My pictures are only an example, but the final stuff I will receive, might contains other bells & whistles like gradients along all the colored arcs, or some texture, etc...

        For these reasons I was trying to use the supplied pictures to animate the gauge.

        R 1 Reply Last reply 19 Feb 2019, 12:09
        0
        • M Mark81
          19 Feb 2019, 12:05

          @raven-worx I can try it but I see two major issues:

          • it would quite hard to perfectly fit each sector if they are not generated automatically using a function (like I would do with mine)
          • it would work only if the requested painting is easy to reproduce. My pictures are only an example, but the final stuff I will receive, might contains other bells & whistles like gradients along all the colored arcs, or some texture, etc...

          For these reasons I was trying to use the supplied pictures to animate the gauge.

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 19 Feb 2019, 12:09 last edited by raven-worx
          #4

          @Mark81 said in Arc gauge:

          it would quite hard to perfectly fit each sector if they are not generated automatically using a function (like I would do with mine)

          For these reasons I was trying to use the supplied pictures to animate the gauge.

          Those 2 sentences are a contradiction no?
          actually you should only paint each sector once and color them differently according to the value.
          I mean it's way harder to place images perfectly than do custom painting at calculated coordinates.

          My pictures are only an example, but the final stuff I will receive, might contains other bells & whistles like gradients along all the colored arcs, or some texture, etc...

          So you want a solution which automagically does everything you need with least effort?

          If you want to work with images (and all it's problems, like blurring etc) the only thing you need is the Image element and probably some effects or masks.
          For a clean solution i would recommend to do the painting yourself, since this gives you also perfect placement and no problems antialiasing.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          M 2 Replies Last reply 19 Feb 2019, 12:26
          1
          • R raven-worx
            19 Feb 2019, 12:09

            @Mark81 said in Arc gauge:

            it would quite hard to perfectly fit each sector if they are not generated automatically using a function (like I would do with mine)

            For these reasons I was trying to use the supplied pictures to animate the gauge.

            Those 2 sentences are a contradiction no?
            actually you should only paint each sector once and color them differently according to the value.
            I mean it's way harder to place images perfectly than do custom painting at calculated coordinates.

            My pictures are only an example, but the final stuff I will receive, might contains other bells & whistles like gradients along all the colored arcs, or some texture, etc...

            So you want a solution which automagically does everything you need with least effort?

            If you want to work with images (and all it's problems, like blurring etc) the only thing you need is the Image element and probably some effects or masks.
            For a clean solution i would recommend to do the painting yourself, since this gives you also perfect placement and no problems antialiasing.

            M Offline
            M Offline
            Mark81
            wrote on 19 Feb 2019, 12:26 last edited by
            #5

            @raven-worx said in Arc gauge:

            Those 2 sentences are a contradiction no?

            At all.
            The pictures are generated, say, with Photoshop changing their color. So if I use them I'm sure they can overlap perfectly each other. On the other hand, if I manually draw both scales, I'm also sure they fit together but it would be harder to reproduce all the graphics effects (and the graphic guy cannot update the images himself - as he requires).

            What I meant with my sentences is it would not work if you use a mix the two approaches - as I thought (wrongly) you suggested before.

            So you want a solution which automagically does everything you need with least effort?

            Uh? I don't understand this question.
            If you see the "QtQuick control extras example" you can find how the CircularGauge is made. For the needle they used a png that rotates according to the requested value. Of course they can draw the needle by hand too, but as said this approach has several
            drawbacks. I don't think its a matter of "doing something automagically" but just to understand how to use the QML tools.

            J.HilkJ 1 Reply Last reply 19 Feb 2019, 12:31
            0
            • R raven-worx
              19 Feb 2019, 12:09

              @Mark81 said in Arc gauge:

              it would quite hard to perfectly fit each sector if they are not generated automatically using a function (like I would do with mine)

              For these reasons I was trying to use the supplied pictures to animate the gauge.

              Those 2 sentences are a contradiction no?
              actually you should only paint each sector once and color them differently according to the value.
              I mean it's way harder to place images perfectly than do custom painting at calculated coordinates.

              My pictures are only an example, but the final stuff I will receive, might contains other bells & whistles like gradients along all the colored arcs, or some texture, etc...

              So you want a solution which automagically does everything you need with least effort?

              If you want to work with images (and all it's problems, like blurring etc) the only thing you need is the Image element and probably some effects or masks.
              For a clean solution i would recommend to do the painting yourself, since this gives you also perfect placement and no problems antialiasing.

              M Offline
              M Offline
              Mark81
              wrote on 19 Feb 2019, 12:27 last edited by
              #6

              @raven-worx said in Arc gauge:

              If you want to work with images (and all it's problems, like blurring etc) the only thing you need is the Image element and probably some effects or masks.

              Yep, and this is the only thing I don't know how to do in this case. Hence my question :-)

              R 1 Reply Last reply 19 Feb 2019, 12:32
              0
              • M Mark81
                19 Feb 2019, 12:26

                @raven-worx said in Arc gauge:

                Those 2 sentences are a contradiction no?

                At all.
                The pictures are generated, say, with Photoshop changing their color. So if I use them I'm sure they can overlap perfectly each other. On the other hand, if I manually draw both scales, I'm also sure they fit together but it would be harder to reproduce all the graphics effects (and the graphic guy cannot update the images himself - as he requires).

                What I meant with my sentences is it would not work if you use a mix the two approaches - as I thought (wrongly) you suggested before.

                So you want a solution which automagically does everything you need with least effort?

                Uh? I don't understand this question.
                If you see the "QtQuick control extras example" you can find how the CircularGauge is made. For the needle they used a png that rotates according to the requested value. Of course they can draw the needle by hand too, but as said this approach has several
                drawbacks. I don't think its a matter of "doing something automagically" but just to understand how to use the QML tools.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on 19 Feb 2019, 12:31 last edited by
                #7

                @Mark81 I think, this will get complicated quite quickly, if you want to do it in pure qml & canvas.

                I would suggest looking into subclassing QQuickPaintedItem that way you can just partially draw the 2nd image, depending on your gauge value.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                M 1 Reply Last reply 19 Feb 2019, 12:40
                1
                • M Mark81
                  19 Feb 2019, 12:27

                  @raven-worx said in Arc gauge:

                  If you want to work with images (and all it's problems, like blurring etc) the only thing you need is the Image element and probably some effects or masks.

                  Yep, and this is the only thing I don't know how to do in this case. Hence my question :-)

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 19 Feb 2019, 12:32 last edited by raven-worx
                  #8

                  @Mark81 said in Arc gauge:

                  Yep, and this is the only thing I don't know how to do in this case. Hence my question :-)

                  assuming your images are identical in size:

                  Image {
                     source: "qrc/background.png"
                  
                     Image {
                         source: "qrc:/foreground.png"
                     }
                  }
                  

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  M 1 Reply Last reply 19 Feb 2019, 12:41
                  0
                  • J.HilkJ J.Hilk
                    19 Feb 2019, 12:31

                    @Mark81 I think, this will get complicated quite quickly, if you want to do it in pure qml & canvas.

                    I would suggest looking into subclassing QQuickPaintedItem that way you can just partially draw the 2nd image, depending on your gauge value.

                    M Offline
                    M Offline
                    Mark81
                    wrote on 19 Feb 2019, 12:40 last edited by
                    #9

                    @J.Hilk said in Arc gauge:
                    that way you can just partially draw the 2nd image, depending on your gauge value.

                    Interesting. Following your approach could not be even easier to draw the colored scale into a Shape element with clip property true. The shape will be a trapezoid with an inclined side starting from the center of the gauges (bound to the value property).

                    I would try it when I understand why "module "QtQuick.Shapes" version 1.12 is not installed" on my system!

                    1 Reply Last reply
                    0
                    • R raven-worx
                      19 Feb 2019, 12:32

                      @Mark81 said in Arc gauge:

                      Yep, and this is the only thing I don't know how to do in this case. Hence my question :-)

                      assuming your images are identical in size:

                      Image {
                         source: "qrc/background.png"
                      
                         Image {
                             source: "qrc:/foreground.png"
                         }
                      }
                      
                      M Offline
                      M Offline
                      Mark81
                      wrote on 19 Feb 2019, 12:41 last edited by
                      #10

                      @raven-worx this does nothing but paints one image one on top of the other....

                      R 1 Reply Last reply 19 Feb 2019, 12:52
                      0
                      • M Mark81
                        19 Feb 2019, 12:41

                        @raven-worx this does nothing but paints one image one on top of the other....

                        R Offline
                        R Offline
                        raven-worx
                        Moderators
                        wrote on 19 Feb 2019, 12:52 last edited by
                        #11

                        @Mark81 said in Arc gauge:

                        @raven-worx this does nothing but paints one image one on top of the other....

                        i thought you get a separate image for each possible value.

                        If you want to keep going the QML-only way take a look at OpacityMask
                        Again for the mask shape you can use a Canvas element drawing an arc to cover the unneeded sectors.

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        M 1 Reply Last reply 19 Feb 2019, 12:56
                        3
                        • R raven-worx
                          19 Feb 2019, 12:52

                          @Mark81 said in Arc gauge:

                          @raven-worx this does nothing but paints one image one on top of the other....

                          i thought you get a separate image for each possible value.

                          If you want to keep going the QML-only way take a look at OpacityMask
                          Again for the mask shape you can use a Canvas element drawing an arc to cover the unneeded sectors.

                          M Offline
                          M Offline
                          Mark81
                          wrote on 19 Feb 2019, 12:56 last edited by
                          #12

                          @raven-worx said in Arc gauge:

                          If you want to keep going the QML-only way take a look at OpacityMask
                          Again for the mask shape you can use a Canvas element drawing an arc to cover the unneeded sectors.

                          Got it. This is a good advice. I'm going to try it and I'll report back the result.
                          Thanks for the patience!

                          1 Reply Last reply
                          0
                          • MarkkyboyM Offline
                            MarkkyboyM Offline
                            Markkyboy
                            wrote on 2 Sept 2024, 22:10 last edited by
                            #13

                            Hi Mark81 - did you achieve your goal?, I realise this question is around 5 years old, but I'm curious to know if you found/created a solution?

                            I have created similar software using CircularSlider/Progress (https://github.com/arunpkio/CircularSlider) with a Repeater, including using Canvas for added circular effects.

                            Don't just sit there standing around, pick up a shovel and sweep up!

                            I live by the sea, not in it.

                            1 Reply Last reply
                            0
                            • JKSHJ Offline
                              JKSHJ Offline
                              JKSH
                              Moderators
                              wrote on 3 Sept 2024, 02:17 last edited by JKSH 9 Mar 2024, 02:18
                              #14

                              Qt 6.8 has just what the doctor ordered (see https://www.youtube.com/watch?v=iXLoC06CKOc):

                              Demo of Qt Quick Effect Maker

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              MarkkyboyM 1 Reply Last reply 3 Sept 2024, 12:35
                              3
                              • JKSHJ JKSH
                                3 Sept 2024, 02:17

                                Qt 6.8 has just what the doctor ordered (see https://www.youtube.com/watch?v=iXLoC06CKOc):

                                Demo of Qt Quick Effect Maker

                                MarkkyboyM Offline
                                MarkkyboyM Offline
                                Markkyboy
                                wrote on 3 Sept 2024, 12:35 last edited by
                                #15

                                @JKSH - Nice!, going to play with that later. Have already developed something similar under Qt 5.6. Not as posh as this one though!

                                Next step, new PC, tablet, monitors and an upgrade to QT6!

                                Don't just sit there standing around, pick up a shovel and sweep up!

                                I live by the sea, not in it.

                                Pl45m4P 1 Reply Last reply 3 Sept 2024, 12:45
                                0
                                • MarkkyboyM Markkyboy
                                  3 Sept 2024, 12:35

                                  @JKSH - Nice!, going to play with that later. Have already developed something similar under Qt 5.6. Not as posh as this one though!

                                  Next step, new PC, tablet, monitors and an upgrade to QT6!

                                  Pl45m4P Offline
                                  Pl45m4P Offline
                                  Pl45m4
                                  wrote on 3 Sept 2024, 12:45 last edited by
                                  #16

                                  @Markkyboy said in Arc gauge:

                                  Nice!, going to play with that later.

                                  Note: 6.8 is still in Beta phase. Final release will be around the end of Sept. with a probably more stable version 6.8.1 even later.


                                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                                  ~E. W. Dijkstra

                                  MarkkyboyM 1 Reply Last reply 3 Sept 2024, 14:41
                                  1
                                  • Pl45m4P Pl45m4
                                    3 Sept 2024, 12:45

                                    @Markkyboy said in Arc gauge:

                                    Nice!, going to play with that later.

                                    Note: 6.8 is still in Beta phase. Final release will be around the end of Sept. with a probably more stable version 6.8.1 even later.

                                    MarkkyboyM Offline
                                    MarkkyboyM Offline
                                    Markkyboy
                                    wrote on 3 Sept 2024, 14:41 last edited by
                                    #17

                                    @Pl45m4 - thanks for the info. By the time I've bought new electronica, it'll likely be available.

                                    Don't just sit there standing around, pick up a shovel and sweep up!

                                    I live by the sea, not in it.

                                    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