Results 1 to 5 of 5

Thread: Cant't draw custom grid

  1. #1
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Cant't draw custom grid

    Hey!
    I'm messing around with the QwtPlotGrid and it's coming along just fine with the exception that I can't manage to make the grid the way I like it. The ticks are in their default position and the interval of the major and minor ticks are changed as the scale is "zoomed" in or out depending on the magnitude of the values plotted/displayed. I want them to be static and custom.

    Let's take a simple example:
    I use the 'histogram'-example from qwt examples.
    Here is the code that generates the grid:
    Qt Code:
    1. QwtValueList vlist[3]; // <-I added this!
    2. vlist[0] << -78 << -66 << -54 << -42 << -30 << -18 << -6 << 6 << 18 << 30;// <-I added this!
    3. vlist[1] << -84 << -60 << -36 << -12 << 12 << 36;// <-I added this!
    4. vlist[2] << -72 << -48 << -24 << 0 << 24;// <-I added this!
    5.  
    6. QwtScaleDiv scdiv(-78, 36, vlist);// <-I added this!
    7.  
    8. QwtPlotGrid *grid = new QwtPlotGrid;
    9. grid->setXDiv(scdiv);// <-I added this!
    10. grid->enableXMin(true);
    11. grid->enableYMin(true);
    12. grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
    13. grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
    14. grid->attach(&plot);
    To copy to clipboard, switch view to plain text mode 

    Why does this code display the same standard grid as when my additions are commented out?
    The goal is to apply the strange scale(grid) from vlist in the X-axis.

    It seems to me that my QwtScaleDiv is OK and from the documentation I get the impression that only the setXDiv command is necessary to apply it to the grid object...

    Thank you!
    /Tottish

  2. #2
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cant't draw custom grid

    OK, so now I have managed to get the scale that I wanted and the custom labels at the ticks where I want them using:
    ui->myPlot->setAxisScaleDiv(0,scdiv);
    So apparently there is nothing wrong with my scaleDiv. However, this doesn't solve my problem since I want aoutoscaling but with custom labels.

    I might as well describe exactly what I'm after since it's a pretty basic concept:
    I want autoscaling as usual but I want the major ticks (with labels) placed only and always at -20,-10,0,10,20,30 and so on and a minor tick (with no label) in between every major.
    I assume I've missed something in the basic functionality of the QwtPlotGrid since it won't display my custom grid without the same fixed, custom scale...

    Peace!
    /Tottish

    EDIT: Hey! And while we're at it, could someone tell me how to change the color of the font in the scales?
    Last edited by Tottish; 20th April 2010 at 13:55.

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,277
    Thanked 871 Times in 819 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cant't draw custom grid

    Quote Originally Posted by Tottish View Post
    Hey!
    I'm messing around with the QwtPlotGrid and it's coming along just fine with the exception that I can't manage to make the grid the way I like it. The ticks are in their default position and the interval of the major and minor ticks are changed as the scale is "zoomed" in or out depending on the magnitude of the values plotted/displayed. I want them to be static and custom.
    If you don't want, that the grid is adjusted to scale changes derive from QwtPlotGrid and reimplement QwtPlotGrid::updateScvaleDiv() to do nothing. But note, that the grid depends on the scale ticks, but is not responsible for their position.

    Uwe

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

    Default Re: Cant't draw custom grid

    However, this doesn't solve my problem since I want aoutoscaling but with custom labels.
    Setting custom ticks is the opposite of autoscaling - so this makes no sense.

    But you can configure the autoscaler, that is part of the QwtScaleEngine for your axis. You also have QwtPlot::setAxisMaxMajor/setAxisMaxMinor to limit the number of intervals ( = ticks ) calculated by the autoscaler.
    I assume I've missed something in the basic functionality of the QwtPlotGrid since it won't display my custom grid without the same fixed, custom scale...
    Yes you do: the grid is responsible for the horizontal/vertical lines according to the scale ticks on the plot canvas. But it has nothing to do with the scales itsself.
    EDIT: Hey! And while we're at it, could someone tell me how to change the color of the font in the scales?
    Depends on which fonts you mean:

    a) Each widget has a setPalette() method - so each QwtScaleWidget has a palette as well.
    b) All labels used in a plot are QwtText objects, that can have their own font/color.

    Uwe

  5. The following user says thank you to Uwe for this useful post:

    Tottish (1st May 2010)

  6. #5
    Join Date
    Mar 2010
    Posts
    77
    Thanks
    17
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cant't draw custom grid

    OK, Thanks Uwe.

Similar Threads

  1. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23
  2. Replies: 5
    Last Post: 21st January 2010, 15:55
  3. Replies: 1
    Last Post: 10th December 2009, 21:31
  4. To draw a custom scale
    By Indalo in forum Qwt
    Replies: 1
    Last Post: 30th November 2009, 13:24
  5. How do I layout in a Grid?
    By DPinLV in forum Qt Tools
    Replies: 7
    Last Post: 10th August 2006, 01:37

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.