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.6k 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.
  • PuntP Punt

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

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on 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.

    PuntP 1 Reply Last reply
    4
    • mrjjM mrjj

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

      PuntP Offline
      PuntP Offline
      Punt
      wrote on 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
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on 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.

        PuntP 1 Reply Last reply
        0
        • mrjjM mrjj

          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.

          PuntP Offline
          PuntP Offline
          Punt
          wrote on 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 :)

          mrjjM 1 Reply Last reply
          0
          • PuntP Punt

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

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #14

            @Punt
            Np. :)

            1 Reply Last reply
            0
            • PuntP Offline
              PuntP Offline
              Punt
              wrote on 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...

              mrjjM 1 Reply Last reply
              0
              • PuntP Punt

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

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on 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.

                PuntP 1 Reply Last reply
                0
                • mrjjM mrjj

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

                  PuntP Offline
                  PuntP Offline
                  Punt
                  wrote on 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)

                  mrjjM 1 Reply Last reply
                  0
                  • PuntP Punt

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

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 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
                    • mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 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.

                      PuntP 1 Reply Last reply
                      1
                      • mrjjM mrjj

                        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.

                        PuntP Offline
                        PuntP Offline
                        Punt
                        wrote on 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
                        • mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 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.

                          mrjjM PuntP 2 Replies Last reply
                          2
                          • mrjjM mrjj

                            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.

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #22

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

                            So u can just change option.rect ( check name)
                            and you can control the size of the dial.

                            PuntP 1 Reply Last reply
                            1
                            • mrjjM mrjj

                              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.

                              PuntP Offline
                              PuntP Offline
                              Punt
                              wrote on last edited by
                              #23

                              @mrjj said:

                              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.

                              If I create a composite class, I don't need anymore my subclass...
                              Well I don't know, I'll check tomorrow if it's easy (Because i'll probably have to change another thing on a QDial => but that's another thing x) )

                              I guess i'll update this topic tomorrow, so if someone has another idea, I take it :)

                              Edit for your last message : I'll check tomorrow, I go home and I can't work there :p

                              See you

                              1 Reply Last reply
                              1
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #24

                                before u try composite, please try adjust paint first.
                                So little code.

                                1 Reply Last reply
                                0
                                • mrjjM mrjj

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

                                  So u can just change option.rect ( check name)
                                  and you can control the size of the dial.

                                  PuntP Offline
                                  PuntP Offline
                                  Punt
                                  wrote on last edited by
                                  #25

                                  @mrjj said:

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

                                  So u can just change option.rect ( check name)
                                  and you can control the size of the dial.

                                  I can't do "option.something" ...

                                  1 Reply Last reply
                                  0
                                  • mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by mrjj
                                    #26

                                    why not?
                                    Look in help then?

                                    http://doc.qt.io/qt-5/qstyleoption.html#rect-var

                                    PuntP 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      why not?
                                      Look in help then?

                                      http://doc.qt.io/qt-5/qstyleoption.html#rect-var

                                      PuntP Offline
                                      PuntP Offline
                                      Punt
                                      wrote on last edited by Punt
                                      #27

                                      @mrjj
                                      Now the problem is I can extend the area and write text in the right and in the bottom of the QDial (because the QDial is drawn (good english ?!) in the left-top (0,0) ). And I don't have any idea how to change that.. I searched if there is something like the position where qt draw of something like that, but didn't find it .. --'

                                      1 Reply Last reply
                                      0
                                      • mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by mrjj
                                        #28

                                        hi
                                        Not tested myself.
                                        option.rect should control where QDial is
                                        and the normal rect is your widget.

                                        So if u set option.rect before
                                        p.drawComplex

                                        U should be able to move it around?

                                        PuntP 1 Reply Last reply
                                        0
                                        • mrjjM mrjj

                                          hi
                                          Not tested myself.
                                          option.rect should control where QDial is
                                          and the normal rect is your widget.

                                          So if u set option.rect before
                                          p.drawComplex

                                          U should be able to move it around?

                                          PuntP Offline
                                          PuntP Offline
                                          Punt
                                          wrote on last edited by
                                          #29

                                          @mrjj
                                          Look, if I

                                          option.rect.setX(20)
                                          

                                          this is just moving one part of the QDial --'
                                          Gyazo

                                          And what do you mean about the normal rect ?

                                          The only rect I have is option.rect no ?!

                                          mrjjM 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