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. QDial pointer start position(value - 0) at top
Forum Update on Monday, May 27th 2025

QDial pointer start position(value - 0) at top

Scheduled Pinned Locked Moved Solved General and Desktop
qdialqslider
12 Posts 4 Posters 2.5k 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 mrjj
    15 Apr 2020, 07:00

    Hi
    Did you try with
    alt text

    If that is not working with Dial then you have to do it manually.

    S Offline
    S Offline
    sayan275
    wrote on 15 Apr 2020, 11:37 last edited by
    #3
    This post is deleted!
    M 1 Reply Last reply 15 Apr 2020, 11:40
    0
    • S sayan275
      15 Apr 2020, 11:37

      This post is deleted!

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 15 Apr 2020, 11:40 last edited by
      #4

      @sayan275
      Hi
      Ok you must have something that block images then.
      Anyway, it show the property
      "inverted appearance "
      that normally flips a slider to be reversed.
      But sadly it didn't work with 0-360 as the zero is still in the bottom.

      http://imagizer.imageshack.com/img922/2451/awXZvi.png

      S 1 Reply Last reply 15 Apr 2020, 11:47
      0
      • M mrjj
        15 Apr 2020, 11:40

        @sayan275
        Hi
        Ok you must have something that block images then.
        Anyway, it show the property
        "inverted appearance "
        that normally flips a slider to be reversed.
        But sadly it didn't work with 0-360 as the zero is still in the bottom.

        http://imagizer.imageshack.com/img922/2451/awXZvi.png

        S Offline
        S Offline
        sayan275
        wrote on 15 Apr 2020, 11:47 last edited by
        #5

        @mrjj sorry I got your posted image..its the property.
        dbfebf2e-5bc1-4907-89ed-a71b586dfc3d-image.png
        Yes it didn't work...I tried all possible combinations with the flags available.
        Can we rotated a widget? .. can't remember any api.
        Meanwhile I got the expected output by calculating with +/- 180

        //    if(value > 180)
        //        value -= 180;
        //    else if(value <= 180)
        //        value += 180;
        

        I didn't want to update the value in this manner.

        @mrjj Anyways thanks for your reply.

        M 1 Reply Last reply 15 Apr 2020, 11:50
        0
        • S sayan275
          15 Apr 2020, 11:47

          @mrjj sorry I got your posted image..its the property.
          dbfebf2e-5bc1-4907-89ed-a71b586dfc3d-image.png
          Yes it didn't work...I tried all possible combinations with the flags available.
          Can we rotated a widget? .. can't remember any api.
          Meanwhile I got the expected output by calculating with +/- 180

          //    if(value > 180)
          //        value -= 180;
          //    else if(value <= 180)
          //        value += 180;
          

          I didn't want to update the value in this manner.

          @mrjj Anyways thanks for your reply.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 15 Apr 2020, 11:50 last edited by
          #6

          @sayan275
          well we cant rotate a widget as such
          but we could subclass it and then flip the painter.
          If that works in terms of navigation, im not sure.

          void QDial::paintEvent(QPaintEvent *)
          {
              QStylePainter p(this);
              QStyleOptionSlider option;
              initStyleOption(&option);
              p.drawComplexControl(QStyle::CC_Dial, option);
          }
          
          

          use p and
          https://doc.qt.io/qt-5/qtwidgets-painting-transformations-example.html
          to flip it and see :)

          S 1 Reply Last reply 15 Apr 2020, 14:23
          1
          • M mrjj
            15 Apr 2020, 11:50

            @sayan275
            well we cant rotate a widget as such
            but we could subclass it and then flip the painter.
            If that works in terms of navigation, im not sure.

            void QDial::paintEvent(QPaintEvent *)
            {
                QStylePainter p(this);
                QStyleOptionSlider option;
                initStyleOption(&option);
                p.drawComplexControl(QStyle::CC_Dial, option);
            }
            
            

            use p and
            https://doc.qt.io/qt-5/qtwidgets-painting-transformations-example.html
            to flip it and see :)

            S Offline
            S Offline
            sayan275
            wrote on 15 Apr 2020, 14:23 last edited by
            #7

            @mrjj Thanks for the suggestion.
            I'll try out the overriding the paintEvent()

            P 1 Reply Last reply 15 Apr 2020, 14:47
            0
            • S sayan275
              15 Apr 2020, 14:23

              @mrjj Thanks for the suggestion.
              I'll try out the overriding the paintEvent()

              P Offline
              P Offline
              Pablo J. Rogina
              wrote on 15 Apr 2020, 14:47 last edited by
              #8

              @sayan275 just in case, do you really need the dial to wrap?

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              S 1 Reply Last reply 17 Apr 2020, 03:00
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 15 Apr 2020, 16:44 last edited by mrjj
                #9

                Hi
                Just as a note.

                void MyDial::paintEvent(QPaintEvent *event)
                {
                    QStylePainter p(this);
                    QStyleOptionSlider option;
                    initStyleOption(&option);
                    p.translate(0, height());
                    p.scale(1.0, -1.0);
                    p.drawComplexControl(QStyle::CC_Dial, option);
                }
                

                Did draw as we wanted and using keys (left , right ) moves it ok
                but click and drag with the mouse it jumps back to the old zero.

                So sadly was not a solution as navigation did went banans.

                1 Reply Last reply
                2
                • P Pablo J. Rogina
                  15 Apr 2020, 14:47

                  @sayan275 just in case, do you really need the dial to wrap?

                  S Offline
                  S Offline
                  sayan275
                  wrote on 17 Apr 2020, 03:00 last edited by
                  #10

                  @Pablo-J-Rogina yes...we need to wrap...so that the starting and endpoints are similar.

                  J 1 Reply Last reply 17 Apr 2020, 06:03
                  0
                  • S sayan275
                    17 Apr 2020, 03:00

                    @Pablo-J-Rogina yes...we need to wrap...so that the starting and endpoints are similar.

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 17 Apr 2020, 06:03 last edited by J.Hilk
                    #11

                    @sayan275
                    here ya go:

                    //.h
                    #ifndef JHDIAL_H
                    #define JHDIAL_H
                    
                    #include <QDial>
                    
                    class JhDial : public QDial
                    {
                        Q_OBJECT
                        Q_PROPERTY(int adjustedValue READ adjustedValue WRITE setAdjustedValue NOTIFY adjustedValueChanged)
                    public:
                        explicit JhDial(QWidget *parent = nullptr);
                    
                        inline int adjustedValue() const { return m_adjustedValue; }
                    
                    signals:
                        void adjustedValueChanged(int adjustedValue);
                    
                    public slots:
                        void setAdjustedValue(int adjustedValue);
                    
                    private:
                        int mapValueToRange(int y, int y_min, int y_max, int x_min, int x_max);
                        void adjustValue(int value);
                        int m_adjustedValue = -1;
                    };
                    
                    #endif // JHDIAL_H
                    
                    
                    //.cpp
                    #include "jhdial.h"
                    
                    JhDial::JhDial(QWidget *parent) : QDial(parent)
                    {
                        connect(this, &QDial::valueChanged, this, &JhDial::adjustValue);
                    
                        setWrapping(true);
                        setRange(0,360);
                        setAdjustedValue(0);
                    }
                    
                    void JhDial::setAdjustedValue(int adjustedValue)
                    {
                        if (m_adjustedValue == adjustedValue)
                            return;
                    
                        if(adjustedValue < 180)
                            setValue(mapValueToRange(adjustedValue,0,179,180,360));
                        else
                            setValue(mapValueToRange(adjustedValue,180,360, 0, 180));
                    
                    }
                    
                    int JhDial::mapValueToRange(int y, int y_min, int y_max, int x_min, int x_max)
                    {
                        return qRound((y-y_min)/static_cast<double>(y_max-y_min)*(x_max-x_min)+x_min);
                    }
                    
                    void JhDial::adjustValue(int value)
                    {
                        if(value < 180)
                            m_adjustedValue = mapValueToRange(value,0, 179, 180, 360);
                        else
                            m_adjustedValue = mapValueToRange(value,180, 360, 0, 180);
                    
                        emit adjustedValueChanged(m_adjustedValue);
                    }
                    
                    

                    You may have to adjust the borders for the mapping, so that they don't overlap, I mad this in a rush ;)
                    you had to, cleaned it up a bit.


                    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.

                    S 1 Reply Last reply 20 Apr 2020, 03:11
                    3
                    • J J.Hilk
                      17 Apr 2020, 06:03

                      @sayan275
                      here ya go:

                      //.h
                      #ifndef JHDIAL_H
                      #define JHDIAL_H
                      
                      #include <QDial>
                      
                      class JhDial : public QDial
                      {
                          Q_OBJECT
                          Q_PROPERTY(int adjustedValue READ adjustedValue WRITE setAdjustedValue NOTIFY adjustedValueChanged)
                      public:
                          explicit JhDial(QWidget *parent = nullptr);
                      
                          inline int adjustedValue() const { return m_adjustedValue; }
                      
                      signals:
                          void adjustedValueChanged(int adjustedValue);
                      
                      public slots:
                          void setAdjustedValue(int adjustedValue);
                      
                      private:
                          int mapValueToRange(int y, int y_min, int y_max, int x_min, int x_max);
                          void adjustValue(int value);
                          int m_adjustedValue = -1;
                      };
                      
                      #endif // JHDIAL_H
                      
                      
                      //.cpp
                      #include "jhdial.h"
                      
                      JhDial::JhDial(QWidget *parent) : QDial(parent)
                      {
                          connect(this, &QDial::valueChanged, this, &JhDial::adjustValue);
                      
                          setWrapping(true);
                          setRange(0,360);
                          setAdjustedValue(0);
                      }
                      
                      void JhDial::setAdjustedValue(int adjustedValue)
                      {
                          if (m_adjustedValue == adjustedValue)
                              return;
                      
                          if(adjustedValue < 180)
                              setValue(mapValueToRange(adjustedValue,0,179,180,360));
                          else
                              setValue(mapValueToRange(adjustedValue,180,360, 0, 180));
                      
                      }
                      
                      int JhDial::mapValueToRange(int y, int y_min, int y_max, int x_min, int x_max)
                      {
                          return qRound((y-y_min)/static_cast<double>(y_max-y_min)*(x_max-x_min)+x_min);
                      }
                      
                      void JhDial::adjustValue(int value)
                      {
                          if(value < 180)
                              m_adjustedValue = mapValueToRange(value,0, 179, 180, 360);
                          else
                              m_adjustedValue = mapValueToRange(value,180, 360, 0, 180);
                      
                          emit adjustedValueChanged(m_adjustedValue);
                      }
                      
                      

                      You may have to adjust the borders for the mapping, so that they don't overlap, I mad this in a rush ;)
                      you had to, cleaned it up a bit.

                      S Offline
                      S Offline
                      sayan275
                      wrote on 20 Apr 2020, 03:11 last edited by
                      #12

                      @J-Hilk Thanks ...I tried this.

                      1 Reply Last reply
                      1

                      12/12

                      20 Apr 2020, 03:11

                      • Login

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