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:
{
public:
{
setRubberBandPen
( QColor( Qt
::darkGreen ) );
}
protected:
{
const QDateTime dt
= QwtDate
::toDateTime( pos.
x() );
s += QwtDate::toString( QwtDate::toDateTime( pos.x() ), "MMM dd hh:mm ", QwtDate::FirstThursday );
text.setColor( Qt::white );
QColor c
= rubberBandPen
().
color();
text.
setBorderPen( QPen( c
) );
text.setBorderRadius( 6 );
c.setAlpha( 170 );
text.setBackgroundBrush( c );
return text;
}
};
class Zoomer: public QwtPlotZoomer
{
public:
Zoomer( QWidget *canvas ): QwtPlotZoomer( canvas )
{
setRubberBandPen( QColor( Qt::darkGreen ) );
setTrackerMode( QwtPlotPicker::AlwaysOn );
}
protected:
virtual QwtText trackerTextF( const QPointF &pos ) const
{
const QDateTime dt = QwtDate::toDateTime( pos.x() );
QString s;
s += QwtDate::toString( QwtDate::toDateTime( pos.x() ), "MMM dd hh:mm ", QwtDate::FirstThursday );
QwtText text( s );
text.setColor( Qt::white );
QColor c = rubberBandPen().color();
text.setBorderPen( QPen( c ) );
text.setBorderRadius( 6 );
c.setAlpha( 170 );
text.setBackgroundBrush( c );
return text;
}
};
To copy to clipboard, switch view to plain text mode
And in my Plot constructor:
PlotWidget
::PlotWidget(QWidget *parent
):{
// LeftButton for the zooming
// RightButton: zoom out by 1
// Ctrl+RighButton: zoom out to full size
Zoomer* zoomer = new Zoomer( canvas() );
zoomer
->setMousePattern
( QwtEventPattern::MouseSelect2, Qt
::RightButton, Qt
::ControlModifier );
// MidButton for the panning
panner->setMouseButton( Qt::MidButton );
_scaleDraw = new DateScaleDraw( Qt::UTC );
_scaleEngine = new QwtDateScaleEngine( Qt::UTC );
setAxisScaleDraw
( QwtPlot::xBottom, _scaleDraw
);
setAxisScaleEngine
( QwtPlot::xBottom, _scaleEngine
);
setAxisLabelRotation
( QwtPlot::xBottom,
-50.0 );
setAxisLabelAlignment
( QwtPlot::xBottom, Qt
::AlignLeft | Qt
::AlignBottom );
}
PlotWidget::PlotWidget(QWidget *parent):
QwtPlot(parent)
{
// LeftButton for the zooming
// RightButton: zoom out by 1
// Ctrl+RighButton: zoom out to full size
Zoomer* zoomer = new Zoomer( canvas() );
zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier );
zoomer->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton );
zoomer->setKeyPattern( QwtEventPattern::KeyHome, Qt::Key_Home );
// MidButton for the panning
QwtPlotPanner *panner = new QwtPlotPanner( canvas() );
panner->setMouseButton( Qt::MidButton );
_scaleDraw = new DateScaleDraw( Qt::UTC );
_scaleEngine = new QwtDateScaleEngine( Qt::UTC );
setAxisScaleDraw( QwtPlot::xBottom, _scaleDraw );
setAxisScaleEngine( QwtPlot::xBottom, _scaleEngine );
setAxisLabelRotation( QwtPlot::xBottom, -50.0 );
setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom );
}
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
Bookmarks