Results 1 to 2 of 2

Thread: Autoscale axis with QwtPlotTradingCurve and set min x axis value

  1. #1
    Join Date
    Jan 2011
    Location
    Paris
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Autoscale axis with QwtPlotTradingCurve and set min x axis value

    Hi all,

    I am new to Qwt. I am able to draw a simple candlestick plot and add some surves for my own indicators. To do so, I have started from the example stockchart.
    As in the example, I also have a zoom:

    Qt Code:
    1. class Zoomer: public QwtPlotZoomer
    2. {
    3. public:
    4. Zoomer( QWidget *canvas ): QwtPlotZoomer( canvas )
    5. {
    6. setRubberBandPen( QColor( Qt::darkGreen ) );
    7. setTrackerMode( QwtPlotPicker::AlwaysOn );
    8. }
    9.  
    10. protected:
    11. virtual QwtText trackerTextF( const QPointF &pos ) const
    12. {
    13. const QDateTime dt = QwtDate::toDateTime( pos.x() );
    14.  
    15. s += QwtDate::toString( QwtDate::toDateTime( pos.x() ), "MMM dd hh:mm ", QwtDate::FirstThursday );
    16.  
    17. QwtText text( s );
    18. text.setColor( Qt::white );
    19.  
    20. QColor c = rubberBandPen().color();
    21. text.setBorderPen( QPen( c ) );
    22. text.setBorderRadius( 6 );
    23. c.setAlpha( 170 );
    24. text.setBackgroundBrush( c );
    25.  
    26. return text;
    27. }
    28. };
    To copy to clipboard, switch view to plain text mode 

    And in my Plot constructor:
    Qt Code:
    1. PlotWidget::PlotWidget(QWidget *parent):
    2. QwtPlot(parent)
    3. {
    4. // LeftButton for the zooming
    5. // RightButton: zoom out by 1
    6. // Ctrl+RighButton: zoom out to full size
    7. Zoomer* zoomer = new Zoomer( canvas() );
    8. zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier );
    9. zoomer->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton );
    10. zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home );
    11. // MidButton for the panning
    12. QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
    13. panner->setMouseButton( Qt::MidButton );
    14.  
    15. _scaleDraw = new DateScaleDraw( Qt::UTC );
    16. _scaleEngine = new QwtDateScaleEngine( Qt::UTC );
    17.  
    18. setAxisScaleDraw( QwtPlot::xBottom, _scaleDraw );
    19. setAxisScaleEngine( QwtPlot::xBottom, _scaleEngine );
    20. setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
    21. setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
    22. }
    To copy to clipboard, switch view to plain text mode 

    OK. Nothing new ... The problems are with the zoom.

    * If I press the home key, I go back to 1 january 1970 (begin of UTC time?). How can I say that the first date in my plot is for instance 1st april 2014 and disallow the user to go before?
    * When I select a zoom region, the values on the y axis are not scaled according to the content, and thus, the plot display "flat" curves. How can I fix this? The same also applies to Ctrl+Right clic.

    Hope you could help

    Best regards

  2. #2
    Join Date
    Jan 2011
    Location
    Paris
    Posts
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Autoscale axis with QwtPlotTradingCurve and set min x axis value

    Problem solved. Had to call
    Qt Code:
    1. _zoomer->setZoomBase();
    To copy to clipboard, switch view to plain text mode 
    and everything works like a charm.

Similar Threads

  1. Axis Title to axis label alignment
    By ROCKSTAR in forum Qwt
    Replies: 0
    Last Post: 5th February 2014, 12:47
  2. Replies: 5
    Last Post: 4th July 2013, 07:24
  3. Replies: 2
    Last Post: 8th July 2011, 00:06
  4. Replies: 9
    Last Post: 3rd May 2011, 21:21
  5. axis autoscale: 2 user case scenarios
    By fatecasino in forum Qwt
    Replies: 1
    Last Post: 19th January 2011, 02:11

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.