Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set different colors?

How to set different colors?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 3 Posters 5.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    n-2204
    wrote on last edited by n-2204
    #7

    @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

    jsulmJ 1 Reply Last reply
    0
    • N n-2204

      @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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        n-2204
        wrote on last edited by
        #9

        CHPlotCurve-Class to draw the data as a line curve

        1 Reply Last reply
        0
        • N Offline
          N Offline
          n-2204
          wrote on last edited by
          #10

          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

          jsulmJ 1 Reply Last reply
          0
          • N n-2204

            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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #11

            @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)...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • N Offline
              N Offline
              n-2204
              wrote on last edited by n-2204
              #12

              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

              jsulmJ 1 Reply Last reply
              0
              • N n-2204

                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

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #13

                @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.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                N 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @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.

                  N Offline
                  N Offline
                  n-2204
                  wrote on last edited by
                  #14

                  @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??

                  jsulmJ 1 Reply Last reply
                  0
                  • N n-2204

                    @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??

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    @n-2204 Come on you already set the color! So, what is your question now?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    N 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @n-2204 Come on you already set the color! So, what is your question now?

                      N Offline
                      N Offline
                      n-2204
                      wrote on last edited by
                      #16

                      @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

                      jsulmJ 1 Reply Last reply
                      0
                      • N n-2204

                        @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

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        @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).

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        N 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @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).

                          N Offline
                          N Offline
                          n-2204
                          wrote on last edited by
                          #18

                          @jsulm ya thanks I knw this .. but problem is I'm taking point from table ..i can't do like this

                          jsulmJ 1 Reply Last reply
                          0
                          • N n-2204

                            @jsulm ya thanks I knw this .. but problem is I'm taking point from table ..i can't do like this

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #19

                            @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...

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • N Offline
                              N Offline
                              n-2204
                              wrote on last edited by n-2204
                              #20

                              @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);

                              jsulmJ 1 Reply Last reply
                              0
                              • N n-2204

                                @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);

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #21

                                @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...

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • N Offline
                                  N Offline
                                  n-2204
                                  wrote on last edited by jsulm
                                  #22
                                  This post is deleted!
                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved