Results 1 to 6 of 6

Thread: Qwt Knobs

  1. #1
    Join Date
    Dec 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qwt Knobs

    Hi,
    I'm developing the interface for an oscilloscope instrument; I would like to use knobs for gain and timescale selections, but the current knobs does not have the required capabilities.

    I'm going to develop myself the required stuff, if needed, but before I write here to ask for suggestions.
    I need a knob with only a set of predefined values in a wide scale range: lets say 1, 2 and 5 as fixed multiplier. I even would like that the scale labels were with the unit specified (as 5us, or 1mV).
    Maybe I can create a my version of QwtRoundScaleDraw, to fix this last point, and I can write a specialized QwtLog10ScaleEngine for the 125 scale. But I need that the knob only selects values in the scale (1, 2 or 5 x scale factor).

    Any idea?

    Alessandro

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt Knobs

    You don't need to implement a scale engine, when you know your ticks in advance. Simply assign them using "knob->setScale(const QwtScaleDiv &)".

    If you need an equidistant scale use a linear scale even if you don't have equidistant values and translate the values of the linear scale into appropriate labels.

    Uwe

  3. #3
    Join Date
    Dec 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qwt Knobs

    Currently I managed it differently, which may not be the best way.
    I use QwtLog10ScaleEngine, and than I do setRange (log10 (min), log10 (max), 0.33). Then I intercept the valueChanged signal and fix there the value
    to the close 1,2,5 tick.
    The only think I don't know is how to reissue the specialized valueChanged signal; now I'm emitting a different signal (which is not really clean). But I didn't see anywhere any doc about polymorphism in signals.

    From what I saw the QwtScaleDiv only regards the scale, not the range: this way when I move the knob it can be set to values not matching any tick in the scale. And this is bad, for me.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt Knobs

    Quote Originally Posted by eto View Post
    From what I saw the QwtScaleDiv only regards the scale, not the range: this way when I move the knob it can be set to values not matching any tick in the scale.
    Well, there is this mysterious QwtAbstractSlider::getScrollMode(). You can try to derive from QwtKnob and overload this method somehow returning QwtAbstractSlider::ScrPage.

    But to be honest: I didn't write these methods myself and havn't seen this code for years. So I'm not sure if this is really a possible solution.

    Uwe

  5. #5
    Join Date
    Dec 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qwt Knobs

    In any case now I fixed as I told, intercepting valueChanged and outputing the right value.

    Now I tried to implement the other point, using text label:
    Qt Code:
    1. class knob125_scale: public QwtRoundScaleDraw {
    2. public:
    3. void drawLabel(QPainter *painter, double value) const {
    4.  
    5. QwtText label(decade_helper::format (value));
    6. label.setRenderFlags(0);
    7. label.setLayoutAttribute(QwtText::MinimumLayout);
    8. label.textSize(painter->font ());
    9.  
    10. if (label.isEmpty ()) return;
    11.  
    12. const int tval = map ().transform (value);
    13. double startAngle = map ().p1 ();
    14. if ((tval > startAngle + 359 * 16) || (tval < startAngle - 359 * 16)) return;
    15.  
    16. double radius = QwtRoundScaleDraw::radius ();
    17. if (hasComponent(QwtAbstractScaleDraw::Ticks) || hasComponent(QwtAbstractScaleDraw::Backbone)) radius += spacing ();
    18.  
    19. if (hasComponent(QwtAbstractScaleDraw::Ticks)) radius += majTickLength ();
    20.  
    21. const QSize sz = label.textSize (painter->font ());
    22. const double arc = tval / 16.0 / 360.0 * 2 * M_PI;
    23.  
    24. const int x = center ().x () + qRound ((radius + sz.width () / 2.0) * sin (arc));
    25. const int y = center ().y () - qRound ((radius + sz.height () / 2.0) * cos (arc));
    26.  
    27. const QRect r(x - sz.width () / 2, y - sz.height () / 2, sz.width (), sz.height ());
    28. label.draw(painter, r);
    29. }
    30. };
    To copy to clipboard, switch view to plain text mode 
    Which is a cut/paste from the corrisponding method of QwtRoundScaleDraw, using decade_helper which is a tool to substitute zeroes with scale (0.03 becomes 30m) .
    This solution is not very clean, but unfortunatelly there is no simple way to have ticks with other than doubles...
    It works but I have some points with the total widget size.

  6. #6
    Join Date
    Dec 2008
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qwt Knobs

    Ops I didn't see the cpuplot example... thanks to the other thread

    Now I reimplemented it in the right way
    Qt Code:
    1. class knob125_scale: public QwtRoundScaleDraw {
    2. public:
    3. virtual QwtText label(double v) const {
    4. return QwtText(decade_helper::format (v));
    5. }
    6. };
    To copy to clipboard, switch view to plain text mode 

    Good.

Similar Threads

  1. Qwt Scale Draw
    By maxpayne in forum Qwt
    Replies: 2
    Last Post: 6th June 2012, 13:01
  2. QWT embedded
    By damien in forum Qwt
    Replies: 3
    Last Post: 20th February 2011, 19:26
  3. QWT introduction
    By nitriles in forum Qwt
    Replies: 4
    Last Post: 28th September 2007, 10:48
  4. How to upgrade Qwt 5.0.1 to Qwt 5.0.2
    By luffy27 in forum Qwt
    Replies: 1
    Last Post: 15th July 2007, 19:55
  5. use interesting QWT Library with QT3.X
    By raphaelf in forum Qwt
    Replies: 2
    Last Post: 23rd January 2006, 11:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.