Results 1 to 8 of 8

Thread: custom axis (setAxisScaleDraw) questions

  1. #1
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default custom axis (setAxisScaleDraw) questions

    Hi,

    From the attached image you see that I have 2 seperate QWtPlots.

    I am implementing a custom Y axis scale via:

    Qt Code:
    1. Status_Graph->setMargin(1);
    2. Status_Graph->enableAxis (QwtPlot::yLeft, true);
    3. m_SimStatusYScaler = new SimStatusYScaleDraw();
    4. Status_Graph->setAxisScaleDraw(QwtPlot::yLeft, m_SimStatusYScaler);
    5. Status_Graph->setAxisScale(QwtPlot::yLeft, 0, 40);
    6. Status_Graph->setAxisLabelAlignment(QwtPlot::yLeft, Qt::AlignLeft | Qt::AlignVCenter);
    To copy to clipboard, switch view to plain text mode 

    There are 2 problems I cannot figure out how to solve.

    1. I would like the space between the Y axis label (ie Run) and the left
    side of the graph itself to be narrower. How/what controls this space?

    2. I would like the 2 graphs to be the same width with their left edges
    aligned. They start out that way
    in QT Designer but when I add the custom Y scale obviously the upper
    graphs narrows.


    Thank you!

    Mark
    Attached Images Attached Images
    Last edited by jpn; 2nd January 2008 at 21:33. Reason: missing [code] tags

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

    Default Re: custom axis (setAxisScaleDraw) questions

    I would like the space between the Y axis label (ie Run) and the left side of the graph itself to be narrower.
    a) QwtAbstractScaleDraw::setSpacing
    b) QwtScaleWidget::setMargin
    I would like the 2 graphs to be the same width with their left edges aligned.
    You have to use QwtScaleDraw::exent/QwtScaleDraw::setMinimumExtent. See the implementation of alignVAxis here: http://qwt.svn.sourceforge.net/viewv...35&view=markup

    Uwe

  3. #3
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom axis (setAxisScaleDraw) questions

    Thanks - that did the trick - awesome..

    I now added a label to the Y-axis and that shifts the graph to
    the right. I assumed I needed to subtract out the label portion
    but the labelSz.height() value alone isn't sufficient to get the
    2 graphs aligned..

    What am I missing?



    // Get the Y-axis label component to subtract out from the extent
    scaleWidget = Simulation_Graph->axisWidget(QwtPlot::yLeft);
    QwtScaleDraw *sd = scaleWidget->scaleDraw();
    QSize labelSz = sd->labelSize(scaleWidget->font(),
    QwtPlot::yLeft);

    scaleWidget = Status_Graph->axisWidget(QwtPlot::yLeft);
    sd = scaleWidget->scaleDraw();
    sd->setMinimumExtent(0);

    const int extent = sd->extent(
    QPen(Qt::black, scaleWidget->penWidth()),
    scaleWidget->font() ) - labelSz.height();
    if ( extent > maxExtent )
    maxExtent = extent;

    scaleWidget = Simulation_Graph->axisWidget(QwtPlot::yLeft);
    scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);

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

    Default Re: custom axis (setAxisScaleDraw) questions

    Quote Originally Posted by MrGarbage View Post
    I now added a label to the Y-axis and that shifts the graph to
    the right.
    What do you mean by label - the axis title ?
    The title of the axis is painted by the QwtScaleWidget, and you find the corresponding layout code in QwtScaleWidget::dimForLength().

    HTH,
    Uwe

  5. #5
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom axis - additional questions

    Hi Uwe,

    I can align my 2 graphs left border now.

    However in some cases I display a 2nd Y-axis on the lower graph.
    When this occurs I want to now shrink the upper graph so that it's
    right border now aligns the right border of the lower graph.

    The upper graph does not implement a 2nd Yaxis.

    I've tried the same sort of logic that I applied on the left border
    including enabling a 2nd Y-axis on the upper graph. Regardless of
    what I do with the extent the upper graph size does not change.

    Any suggestion on how to accomplish this?

    At some point I want to synchronize these 2 graphs such that if
    I zoom one, the other zooms as well. They share a common X-axis.
    Are there any examples out there of code that implements this sort
    of thing?


    Many thanks

    Mark
    Attached Images Attached Images

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,278
    Thanked 872 Times in 820 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: custom axis - additional questions

    However in some cases I display a 2nd Y-axis on the lower graph.
    When this occurs I want to now shrink the upper graph so that it's
    right border now aligns the right border of the lower graph.
    You need to add an additional spacer to the right of your upper plot. AFAIR it is possible to use a dummy right axis with no title and where all components of the scale draw are hidden ( QwtAbstractScaleDraw::enableComponent(..., false ). Then you can align the right axes like you did it with the left one.

    A more clean situation is to use an QHBoxLayout and put the upper plot and a spacer QWidget into it.
    At some point I want to synchronize these 2 graphs such that if
    I zoom one, the other zooms as well. They share a common X-axis.
    QwtPlotZoomer emits zoomed signals. You can also use the scaleDivChanged() signal of the scale widgets, but you need to be careful to avoid ping pong effects.

    HTH,
    Uwe

  7. #7
    Join Date
    Mar 2007
    Posts
    74
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: custom axis (setAxisScaleDraw) questions

    Hi Uwe,

    I don't seem to be able to effect the size of the graph from the Right
    Y-axis side at all. Setting a minExtent makes no difference. I have tried
    with and without components enabled. I also added a spacer to the right
    and layed that out Horizontally.

    For example with a backbone enabled on the YRight I see the backbone and
    the graph width has initially been adjusted so that the backbone appears
    to the right.

    The realtime example uses the method you suggested to keep the plot from
    jumping all over the place when the YLeft axislabels change.

    If there were also a YRight axis and labels for that example
    would we not have the same problem?

    Where/how does qwt adjust the graph size to accomodate the YRight components?

    Any suggestions as to how to proceed?

    Thanks
    Mark

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,278
    Thanked 872 Times in 820 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: custom axis (setAxisScaleDraw) questions

    Any suggestions as to how to proceed?
    Have a look at the plotmatrix example in the Qwt SVN (trunk).
    You can build Qwt 5.1 snapshot from it, to see how the plotmatrix example works.

    Uwe

Similar Threads

  1. Qwt and custom axis
    By jiveaxe in forum Qwt
    Replies: 3
    Last Post: 14th November 2007, 15:50

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.