Results 1 to 6 of 6

Thread: scale widget with major tick in the middle

  1. #1
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default scale widget with major tick in the middle

    Hi,
    I am trying to have a ScaleWidget that has a Major tick in the middle of
    the interval for the scale. What is the best way to achieve this?

    I tried:



    QwtLinearScaleEngine scaleEngine;
    scaleEngine.setAttribute (QwtScaleEngine::IncludeReference);
    scaleEngine.setAttribute (QwtScaleEngine::Floating);
    scaleEngine.setReference ((interval.minValue () + interval.maxValue
    ()) / 2);
    scaleEngine.setMargins (0, 0);
    scaleWidgetColorBar->setScaleDiv (
    scaleEngine.transformation (),
    scaleEngine.divideScale (
    interval.minValue (), interval.maxValue (), 3, 10));


    However, IncludeReference and Floating attributes don't seem to have any
    effect.

    Thanks a lot,
    Dan

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

    Default Re: scale widget with major tick in the middle

    Quote Originally Posted by dlipsa View Post
    I am trying to have a ScaleWidget that has a Major tick in the middle of the interval for the scale.
    Qt Code:
    1. QList<double> ticks[QwtScaleDiv::NTickTypes];
    2. ....
    3. ticks[QwtScaleDiv::MajorTick] += interval.minValue () + interval.maxValue()) / 2);
    4.  
    5. plot->setAxisScaleDiv(..., QwtScaleDiv(interval, ticks);
    To copy to clipboard, switch view to plain text mode 
    HTH,
    Uwe

  3. #3
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: scale widget with major tick in the middle

    Hi Uwe,
    Thanks for your answer.
    I am trying to use a a QwtScaleWidget by itself, without a plot. I have tried something similar with what you sugested, but that did not produce any ticks.


    Here is the code I have. The version using a LinearScaleEngine produces major ticks but the middle one is not centered. The commented code did not produce any ticks.

    Do you have any ideas or suggestions?
    Thanks a lot!

    QwtLinearScaleEngine scaleEngine;
    scaleEngine.setAttribute (QwtScaleEngine::IncludeReference);
    scaleEngine.setAttribute (QwtScaleEngine::Floating);
    scaleEngine.setReference (
    (interval.minValue () + interval.maxValue ()) / 2);
    scaleEngine.setMargins (0, 0);
    scaleWidgetColorBar->setScaleDiv (
    scaleEngine.transformation (),
    scaleEngine.divideScale (
    interval.minValue (), interval.maxValue (), 3, 10));

    /*
    QwtScaleDiv scaleDiv;
    QwtValueList tickList;
    tickList.append ((interval.minValue () + interval.maxValue ()) / 2);
    scaleDiv.setInterval (interval);
    scaleDiv.setTicks (QwtScaleDiv::MajorTick, tickList);
    scaleWidgetColorBar->setScaleDiv (
    new QwtScaleTransformation (QwtScaleTransformation::Linear), scaleDiv);
    */
    setupBlueRedColorMap (&m_colorMap);
    scaleWidgetColorBar->setColorMap (interval, m_colorMap);

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

    Default Re: scale widget with major tick in the middle

    The scale engine calculates a QwtScaleDiv, but of course you have to do something with it:

    Qt Code:
    1. ...
    2. QwtScaleDiv scaleDiv = scaleEngine.divideScale(...);
    3. QwtValueList majorTicks = scaleDiv.ticks[QwtScaleDiv::MajorTick];
    4. majorTicks += interval.minValue () + interval.maxValue()) / 2);
    5. scaleDiv.setTicks(QwtScaleDiv::MajorTick, majorTicks);
    6. scaleWidgetColorBar->setScaleDiv (..., scaleDiv);
    To copy to clipboard, switch view to plain text mode 
    Of course you can compose your QwtScaleDiv object manually without using a scale engine as well.

    Uwe

  5. #5
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: scale widget with major tick in the middle

    Great. Thanks a lot!
    The following code does exactly what I want: get a scale with the min, max and middle of the interval marked.

    QwtLinearScaleEngine scaleEngine;
    QwtScaleDiv scaleDiv = scaleEngine.divideScale (
    interval.minValue (), interval.maxValue (), 0, 0);
    QwtValueList majorTicks;
    majorTicks += (interval.minValue () + interval.maxValue()) / 2;
    majorTicks += interval.minValue ();
    majorTicks += interval.maxValue ();
    scaleDiv.setTicks(QwtScaleDiv::MajorTick, majorTicks);
    scaleWidgetColorBar->setScaleDiv (scaleEngine.transformation (), scaleDiv);


    Do you have any suggestions on how to get rid of the scale engine? It seems strange to use the scale engine just to get no division. However that was
    the only was I could get divisions on the scaleDiv. Thanks again!
    Dan

  6. #6
    Join Date
    Jul 2010
    Posts
    4
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: scale widget with major tick in the middle

    Hi Uwe,
    Another related question is: How do tell the LinearScaleEngine to start the minor ticks in the middle of the scale?
    I thought QwtScaleEngine::IncludeReference should work, but unfortunately it did not work fo me. (see the above code)

    Thanks a lot!

Similar Threads

  1. Grid Minor Major and gap before the data
    By huseyinkozan in forum Qwt
    Replies: 3
    Last Post: 3rd August 2010, 12:13
  2. Replies: 0
    Last Post: 4th May 2010, 09:45
  3. Scale a widget
    By yagabey in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2008, 13:08
  4. qwtscalewidget: setting scale to the widget..
    By halberdier83 in forum Qwt
    Replies: 3
    Last Post: 4th December 2007, 08:08
  5. My own scale widget in Qwt
    By igrms in forum Qwt
    Replies: 7
    Last Post: 15th June 2006, 21:18

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.