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. How do I subclass QDial to show notches values ?
Forum Updated to NodeBB v4.3 + New Features

How do I subclass QDial to show notches values ?

Scheduled Pinned Locked Moved Solved General and Desktop
39 Posts 2 Posters 13.3k Views 1 Watching
  • 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
    mrjj
    Lifetime Qt Champion
    wrote on 26 Apr 2016, 09:35 last edited by
    #2

    Hi
    What about just placing a label next to the dial (or on top of it)
    hook up the void valueChanged(int value)
    to a slot in main
    and then simple change the text in the label when dial is changed?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Punt
      wrote on 26 Apr 2016, 09:53 last edited by
      #3

      Because I need to see all of the values...
      And I can't put x label for x values, because I load a XML which say how many QDial I need ^^'
      and the values aren't the same for all of the QDial...

      (sorry if my english is bad x) )

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 26 Apr 2016, 10:00 last edited by
        #4

        Hi
        Your English is fine but its not clear how this Dial should look like

        So INSTEAD of values/small ticks on the Dial, you want text `?
        So first little tick is Hello etc ?

        P 1 Reply Last reply 26 Apr 2016, 11:13
        0
        • M mrjj
          26 Apr 2016, 10:00

          Hi
          Your English is fine but its not clear how this Dial should look like

          So INSTEAD of values/small ticks on the Dial, you want text `?
          So first little tick is Hello etc ?

          P Offline
          P Offline
          Punt
          wrote on 26 Apr 2016, 11:13 last edited by
          #5

          @mrjj
          Something like that :
          Gyazo Link

          M 1 Reply Last reply 26 Apr 2016, 11:16
          0
          • P Punt
            26 Apr 2016, 11:13

            @mrjj
            Something like that :
            Gyazo Link

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 26 Apr 2016, 11:16 last edited by
            #6

            @Punt
            Ok
            You can sublass it and override the paintEvent
            make it paint as normal, and then paint the text on top.
            But you show 4 texts, do you have more for real app?

            P 2 Replies Last reply 26 Apr 2016, 11:19
            0
            • M mrjj
              26 Apr 2016, 11:16

              @Punt
              Ok
              You can sublass it and override the paintEvent
              make it paint as normal, and then paint the text on top.
              But you show 4 texts, do you have more for real app?

              P Offline
              P Offline
              Punt
              wrote on 26 Apr 2016, 11:19 last edited by
              #7

              @mrjj
              I would like to have a subclass which will work with 3 to 6 values..

              Because, at the end, my app need to be adaptable/adjustable as the user(not me) want !

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 26 Apr 2016, 11:21 last edited by
                #8

                Hi
                Well then subclass will work best as you can add support
                for having a list of TickTexts or what u call them :)

                1 Reply Last reply
                0
                • M mrjj
                  26 Apr 2016, 11:16

                  @Punt
                  Ok
                  You can sublass it and override the paintEvent
                  make it paint as normal, and then paint the text on top.
                  But you show 4 texts, do you have more for real app?

                  P Offline
                  P Offline
                  Punt
                  wrote on 26 Apr 2016, 11:56 last edited by
                  #9

                  @mrjj said:

                  @Punt
                  Ok
                  You can sublass it and override the paintEvent
                  make it paint as normal, and then paint the text on top.
                  But you show 4 texts, do you have more for real app?

                  I know how to subclass & override, but "make it paint as normal and then paint the text", I don't have any idea how to do it ...

                  M 1 Reply Last reply 26 Apr 2016, 12:00
                  0
                  • P Punt
                    26 Apr 2016, 11:56

                    @mrjj said:

                    @Punt
                    Ok
                    You can sublass it and override the paintEvent
                    make it paint as normal, and then paint the text on top.
                    But you show 4 texts, do you have more for real app?

                    I know how to subclass & override, but "make it paint as normal and then paint the text", I don't have any idea how to do it ...

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 26 Apr 2016, 12:00 last edited by
                    #10

                    @Punt
                    Oh sorry being unclear
                    When you have overridden paint
                    in top you call the base class
                    void mycooldial::paintEvent( ..
                    QDial::PaintEvent(event); << call the normal paint

                    then after u paint text on top of it.

                    P 1 Reply Last reply 26 Apr 2016, 12:54
                    4
                    • M mrjj
                      26 Apr 2016, 12:00

                      @Punt
                      Oh sorry being unclear
                      When you have overridden paint
                      in top you call the base class
                      void mycooldial::paintEvent( ..
                      QDial::PaintEvent(event); << call the normal paint

                      then after u paint text on top of it.

                      P Offline
                      P Offline
                      Punt
                      wrote on 26 Apr 2016, 12:54 last edited by
                      #11

                      @mrjj
                      OK here I am :

                      .h :

                      #ifndef CUSTOMDIAL_H
                      #define CUSTOMDIAL_H
                      
                      #include <QObject>
                      #include <QDial>
                      
                      class CustomDial : public QDial
                      {
                          Q_OBJECT
                      
                      public:
                      
                          CustomDial(QWidget * parent = nullptr,
                                     double knobRadius = 5,
                                     double knobMargin = 5);
                      
                      private:
                      
                          virtual void paintEvent(QPaintEvent*pe) override;
                      
                      };
                      
                      #endif // CUSTOMDIAL_H
                      
                      

                      .cpp :

                      #include "customdial.h"
                      
                      CustomDial::CustomDial(QWidget* parent,
                                             double knobRadius,
                                             double knobMargin)
                      : QDial(parent)
                      {
                          // Default range
                          QDial::setRange(0,100);
                      }
                      
                      void CustomDial::paintEvent(QPaintEvent* pe)
                      {    QDial::paintEvent(pe);
                      
                      }
                      
                      

                      It seems to work, I have my QDial then I'll try to add my text...

                      But I have :

                      QMetaObject::connectSlotsByName: No matching signal for on_pushButton_pressed()
                      QMetaObject::connectSlotsByName: No matching signal for on_pushButton_clicked()
                      QMetaObject::connectSlotsByName: No matching signal for on_pushButton_released()
                      QMetaObject::connectSlotsByName: No matching signal for on_dial_valueChanged(int)
                      
                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 26 Apr 2016, 13:00 last edited by
                        #12

                        Hmm
                        you dont show any connect statements?

                        So this from other part of project.

                        This might happen if you add slot by right clicking in Creator and then later rename slot or the button/widget
                        Its not related to the subclass as such.

                        P 1 Reply Last reply 26 Apr 2016, 13:05
                        0
                        • M mrjj
                          26 Apr 2016, 13:00

                          Hmm
                          you dont show any connect statements?

                          So this from other part of project.

                          This might happen if you add slot by right clicking in Creator and then later rename slot or the button/widget
                          Its not related to the subclass as such.

                          P Offline
                          P Offline
                          Punt
                          wrote on 26 Apr 2016, 13:05 last edited by
                          #13

                          @mrjj
                          Oh sorry my bad to disturb you for this..
                          This is SLOT that I used earlier to try things with QDial --'

                          Ok I'll try to paint my text now :)

                          M 1 Reply Last reply 26 Apr 2016, 13:06
                          0
                          • P Punt
                            26 Apr 2016, 13:05

                            @mrjj
                            Oh sorry my bad to disturb you for this..
                            This is SLOT that I used earlier to try things with QDial --'

                            Ok I'll try to paint my text now :)

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 26 Apr 2016, 13:06 last edited by
                            #14

                            @Punt
                            Np. :)

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              Punt
                              wrote on 26 Apr 2016, 13:50 last edited by
                              #15

                              Ok, I understand how it works.. I have an idea to determinate the position of my texts (unit cercle I guess).

                              But I have a problem, because for example (with a QDial 100x100) :

                              • if I add text in (0,50) a part of the text will be on the QDial..
                              • if I add text in (-10,50), a part of the text will be cut

                              I guess I have to extend the painting zone.. but I don't find anything...

                              M 1 Reply Last reply 26 Apr 2016, 14:29
                              0
                              • P Punt
                                26 Apr 2016, 13:50

                                Ok, I understand how it works.. I have an idea to determinate the position of my texts (unit cercle I guess).

                                But I have a problem, because for example (with a QDial 100x100) :

                                • if I add text in (0,50) a part of the text will be on the QDial..
                                • if I add text in (-10,50), a part of the text will be cut

                                I guess I have to extend the painting zone.. but I don't find anything...

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 26 Apr 2016, 14:29 last edited by
                                #16

                                @Punt
                                Hi the
                                "Painting zone" is the size of the QDial
                                You cannot paint outside it using -100 for x
                                It clip clip as you saw.
                                You cannot increase this area unless its ok the QDial also becomes bigger.

                                P 1 Reply Last reply 26 Apr 2016, 14:38
                                0
                                • M mrjj
                                  26 Apr 2016, 14:29

                                  @Punt
                                  Hi the
                                  "Painting zone" is the size of the QDial
                                  You cannot paint outside it using -100 for x
                                  It clip clip as you saw.
                                  You cannot increase this area unless its ok the QDial also becomes bigger.

                                  P Offline
                                  P Offline
                                  Punt
                                  wrote on 26 Apr 2016, 14:38 last edited by Punt
                                  #17

                                  @mrjj
                                  Maybe I can reduce the QDial then ? Like the radius of the circle ?

                                  Or last idea : I create a new class, in which I put an "aera" like a Widget (?), I add a QDial and I draw my "notches-text-values" (Still don't know how to call it xDD)

                                  M 1 Reply Last reply 26 Apr 2016, 14:43
                                  0
                                  • P Punt
                                    26 Apr 2016, 14:38

                                    @mrjj
                                    Maybe I can reduce the QDial then ? Like the radius of the circle ?

                                    Or last idea : I create a new class, in which I put an "aera" like a Widget (?), I add a QDial and I draw my "notches-text-values" (Still don't know how to call it xDD)

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 26 Apr 2016, 14:43 last edited by
                                    #18

                                    @Punt
                                    well maybe. i dont think so.
                                    I think it uses all its area.
                                    else u need to copy the paint function and alter it to allow
                                    to paint smaller than the area.
                                    You should look in source and see what it uses to better understand it.

                                    1 Reply Last reply
                                    2
                                    • M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 26 Apr 2016, 14:45 last edited by
                                      #19

                                      sorry I miss last part.

                                      Yes also option to make a composite class where u have QDial in center ( in a layout) and
                                      let ur class paint on top of it all.

                                      P 1 Reply Last reply 26 Apr 2016, 14:49
                                      1
                                      • M mrjj
                                        26 Apr 2016, 14:45

                                        sorry I miss last part.

                                        Yes also option to make a composite class where u have QDial in center ( in a layout) and
                                        let ur class paint on top of it all.

                                        P Offline
                                        P Offline
                                        Punt
                                        wrote on 26 Apr 2016, 14:49 last edited by
                                        #20

                                        @mrjj
                                        I think I'll go for it !
                                        It's the easiest solution I guess...

                                        I'm done for today, I'll try it tomorrow :)
                                        Thanks :)

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 26 Apr 2016, 14:49 last edited by
                                          #21

                                          but since you already subclassed it, why not make it work 100% like u want?
                                          Also need to be able to give list for the "tick words" etc.
                                          So find the source and see the paitnevent
                                          maybe its easy to modify for what u want.

                                          M P 2 Replies Last reply 26 Apr 2016, 14:53
                                          2

                                          11/39

                                          26 Apr 2016, 12:54

                                          topic:navigator.unread, 28
                                          • Login

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