I'm overloading the drawCanvas method to display text on my QwtPlotHistogram. However when i zoom or scroll the text remains in a fixed position. I want the text to move along with the rectangles of the histogram when i scroll or zoom
I'm overloading the drawCanvas method to display text on my QwtPlotHistogram. However when i zoom or scroll the text remains in a fixed position. I want the text to move along with the rectangles of the histogram when i scroll or zoom
Of course you have to align your labels to the translated positions ( QwtScaleMap::transform ).
When you overload QwtPlotHistogram::draw instead you already have the maps - otherwise you get them using QwtPlot::canvasMap.
Uwe
Could you point me to an example where this is done or QwtScaleMap has been used?
Qwt ?
Uwe
By example i mean some Qwt code where this has been implemented.. i cannot understand how to use it in my code..
Plot items implemented in Qwt doesn't differ from those, that are implemented in application code.
Uwe
Which application?
What coordinates are you using for the text? Pixels or data coordinates? If you are using pixels, then of course the text will not move. So you need to define the text location in data coordinates, and use QwtScaleMap to transform the data coordinates into pixels when drawing.
Look at the Qwt source code for any QwtPlotItem class to see how to use the scale maps. QwtPlotCurve::drawSticks() (from Qwt 5.2) is a simple example:
Qt Code:
00732 int from, int to) const 00733 { 00734 int x0 = xMap.transform(d_data->reference); 00735 int y0 = yMap.transform(d_data->reference); 00736 00737 for (int i = from; i <= to; i++) 00738 { 00739 const QwtDoublePoint sample = d_series->sample(i); 00740 const int xi = xMap.transform(sample.x()); 00741 const int yi = yMap.transform(sample.y()); 00742 00743 if (orientation() == Qt::Horizontal) 00745 else 00747 } 00748 }To copy to clipboard, switch view to plain text mode
Bookmarks