How to draw polyline using vector computed from another class
Hi,
I am having trouble draw a polyline from a vector of QPointF which is calculated in another class "getAvgHighTempVec".
Here is my code:
Code:
// main.cpp
size_t qpoint_size = c.getAvgHighTempVec().size();
QVector<QPointF> points(qpoint_size);
for(size_t i=0; i < qpoint_size; i++){
points[i].setX(i);
points[i].setY(c.getAvgHighTempVec().at(i));
}
weatherStationGUI.draw(points);
Code:
//weatherstationgui.h
namespace Ui {
class weatherstationgui;
}
{
Q_OBJECT
public:
explicit weatherstationgui
(QWidget *parent
= 0);
~weatherstationgui();
void draw( QVector<QPointF> dataIn);
private:
Ui::weatherstationgui *ui;
QVector<QPointF> wellData;
protected:
// paint method
};
Code:
//weatherstationgui.cpp
void weatherstationgui::draw(QVector<QPointF> dataIn){
wellData = dataIn;
update();
}
void weatherstationgui
::paintEvent(QPaintEvent *event
){
// create a painter
painter.drawPolyline(wellData.data(), static_cast<int>(wellData.size()));
}
In the debugger I can see 'wellData' indeed has the correct QPointF points values, but it just doesn't draw on the main window.
Is there anything wrong with my code?
Thanks
Re: How to draw polyline using vector computed from another class
What are typical values in the points array? As you have presented it these values will be treated as equivalent to pixel coordinates.
Re: How to draw polyline using vector computed from another class
yes, you are absolutely right. The values stored in the vector points are the coordinates. It looks like { (1.6, 0) , (2.3, 1) ...} in debugger.
Re: How to draw polyline using vector computed from another class
Your points are being drawn in a few pixels in the top left of the window. You need to scale the values yourself or use a transform on the painter to do it for you.
See Coordinate transforms
Re: How to draw polyline using vector computed from another class
Thank you Chris! its been there all the time but I chose to ignore it ;)