Solved How to set different colors?
-
Ok..
I'm also asking like how to set color for each line that will be drawn using table data -
@n-2204 said in How to set different colors?:
I'm also asking like how to set color for each line that will be drawn using table data
You're already setting color:
line->setPen(Qt::blue, 2, Qt::SolidLine)
Simply set the color you want to set for a specific line. I really fail to understand what the problem is...
-
@jsulm ya using this every line get same color..
but i need to set color when 1,2 line drawn , third , fourth
which is based on no of entries in table column x, y -
@n-2204 If your line consists of more than one segment, then you will need to explain how CHPlotCurve works (show its code). How does it draw each segment? You could have something like setColors(QVector<QColor> colors) to specify colors for all segments.
-
CHPlotCurve-Class to draw the data as a line curve
-
QVector<QColor> colors = { QColor(255,0,0), QColor(0,255,0), QColor(0,0,255),
QColor(0,0,0), QColor(255,255,255), QColor(0,128,64) };
for(int i=0;i<6;i++)
line->setPen(colors[i]);
}
i unable to set diff color..using this code only same color lines drawn..as i value in not incremented when second time line drawn ?
what changes req..?any suggestions -
@n-2204 said in How to set different colors?:
i unable to set diff color..using this code only same color lines drawn
Of course it can't work this way! And it is not what I suggested! Please read my post once more...
That's why I asked how your class actually draws. You still did not answer this question (I have no idea how CHPlotCurve does the drawing)... -
I'm using these predefined classes..
@jsulm CHPlotCurve -Class to draw the data as a line curve in the graph canvas area(x-y plane).
CHPlotCurve--derived from QwtPlotCurve class
void CHPlotCurve::setSamples(QwtSeriesData<QPointF> *). CHPlotCurveData is derived from QwtSeriesData<QPointF>. This function is part of the one of the base class of CHPlotCurve.
There are two ways to set color is using setBrush or setpen -
@n-2204 If there is no support for different colors for different segments of a line then you can still draw each segment separately as one line.
-
@jsulm yes.. line able to draw.. but how i set color for these line.. like line drawn then how can i set a color to that??
-
@n-2204 Come on you already set the color! So, what is your question now?
-
@jsulm yes.. this color will be same for each line drawn .. but i need to set diff color for 1,2 3 etc lines... thats why i tried using loop
-
@n-2204 If you can set color for one line then you can set color for every line. Something like:
// Line 1 QPointF pt1(X, Y); WHAT_EVER_LINE_DATA_IS linedata1; linedata1->append(pt1); CHPlotCurve* line1 = (CHPlotCurve*)pGr->insertCurve("line", CHPlotGraph2D::Line, false); line1->setSamples(linedata1); line1->setPen(Qt::blue, 2, Qt::SolidLine); // Line 2 QPointF pt2(X2, Y2); WHAT_EVER_LINE_DATA_IS linedata2; linedata2->append(pt2); CHPlotCurve* line2 = (CHPlotCurve*)pGr->insertCurve("line", CHPlotGraph2D::Line, false); line2->setSamples(linedata2); line2->setPen(Qt::red, 2, Qt::SolidLine)
Also, please consider that this CHPlotCurve is not part of Qt, you should consider checking its documentation and ask in a different forum (if there is one).
-
@jsulm ya thanks I knw this .. but problem is I'm taking point from table ..i can't do like this
-
@n-2204 said in How to set different colors?:
I'm taking point from table
So what?
Take the points from the table, I don't see how this stops you from doing it the way I suggested... -
@jsulm I have 8 rows in table so i will do 8 times first store every row data then do this ? is this a way ?
Thanks for your answers.
every time i take point ..create line data and pass to line
CHPlotCurveData* linedata1 = new CHPlotCurveData();
CHPlotCurve* line = (CHPlotCurve*)pGr->insertCurve("line", CHPlotGraph2D::Line, false); -
@n-2204 Simply iterate over the rows of your table in a loop. For each row take the point coordinates, create the line, set color...
-
This post is deleted!