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. coloring a part of a line (QLineF)

coloring a part of a line (QLineF)

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.2k Views
  • 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.
  • B Offline
    B Offline
    Bikram Shishodia
    wrote on last edited by
    #1

    Hi,

    I am drawing a line using QLineF and QPainter and coloring the same by setting pen color and painter brush.
    QLineF line1;
    QPen pen = QPen(WHITE,THICKNESS);
    painter.setBrush(QBrush(WHITE));
    painter.setPen(pen);
    painter.drawLine(line1);
    But its coloring the whole line(As expected)
    0_1559032510990_d9c9f84e-694a-410c-9afa-95e73a09d192-image.png

    Now I want to color some part of the same line with different color like:(No other QLineF object should be used)
    0_1559032583343_58a51d89-350c-4c76-bf95-06ceef8bc667-image.png

    Is this possible?
    If yes, Please give me some idea.
    Thanks in Advance :)

    jsulmJ JKSHJ Pradeep P NP 3 Replies Last reply
    0
    • B Bikram Shishodia

      Hi,

      I am drawing a line using QLineF and QPainter and coloring the same by setting pen color and painter brush.
      QLineF line1;
      QPen pen = QPen(WHITE,THICKNESS);
      painter.setBrush(QBrush(WHITE));
      painter.setPen(pen);
      painter.drawLine(line1);
      But its coloring the whole line(As expected)
      0_1559032510990_d9c9f84e-694a-410c-9afa-95e73a09d192-image.png

      Now I want to color some part of the same line with different color like:(No other QLineF object should be used)
      0_1559032583343_58a51d89-350c-4c76-bf95-06ceef8bc667-image.png

      Is this possible?
      If yes, Please give me some idea.
      Thanks in Advance :)

      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Bikram-Shishodia I don't think it is possible but nothing stops you from drawing two lines with different colors.
      "No other QLineF object should be used" - why not? It's not a big object.

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

      1 Reply Last reply
      5
      • B Bikram Shishodia

        Hi,

        I am drawing a line using QLineF and QPainter and coloring the same by setting pen color and painter brush.
        QLineF line1;
        QPen pen = QPen(WHITE,THICKNESS);
        painter.setBrush(QBrush(WHITE));
        painter.setPen(pen);
        painter.drawLine(line1);
        But its coloring the whole line(As expected)
        0_1559032510990_d9c9f84e-694a-410c-9afa-95e73a09d192-image.png

        Now I want to color some part of the same line with different color like:(No other QLineF object should be used)
        0_1559032583343_58a51d89-350c-4c76-bf95-06ceef8bc667-image.png

        Is this possible?
        If yes, Please give me some idea.
        Thanks in Advance :)

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        @Bikram-Shishodia said in coloring a part of a line (QLineF):

        (No other QLineF object should be used)

        Is this possible?

        No. You need another QLineF object.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        2
        • B Bikram Shishodia

          Hi,

          I am drawing a line using QLineF and QPainter and coloring the same by setting pen color and painter brush.
          QLineF line1;
          QPen pen = QPen(WHITE,THICKNESS);
          painter.setBrush(QBrush(WHITE));
          painter.setPen(pen);
          painter.drawLine(line1);
          But its coloring the whole line(As expected)
          0_1559032510990_d9c9f84e-694a-410c-9afa-95e73a09d192-image.png

          Now I want to color some part of the same line with different color like:(No other QLineF object should be used)
          0_1559032583343_58a51d89-350c-4c76-bf95-06ceef8bc667-image.png

          Is this possible?
          If yes, Please give me some idea.
          Thanks in Advance :)

          Pradeep P NP Offline
          Pradeep P NP Offline
          Pradeep P N
          wrote on last edited by
          #4

          @Bikram-Shishodia
          As said by @jsulm & @JKSH you can use multiple QLine or QLineF with QPainter::drawLines

          // QPainter::drawLines Options available 
          
          void QPainter::drawLines(const QVector<QLine> &lines)
          void QPainter::drawLines(const QVector<QLineF> &lines)
          etc...
          

          Here is sample code, where you have to draw individual lines without QLine or QLineF

              QPainter painter(this);
          
              painter.setPen(QPen(Qt::red, 5));
              painter.drawLine(100, 50, 150, 50);
              painter.setPen(QPen(Qt::green, 5));
              painter.drawLine(150, 50, 200, 50);
          

          Output:
          0_1559102535212_bcbd4e22-1266-44fe-b8e3-f13cafb3b3df-image.png

          Pradeep Nimbalkar.
          Upvote the answer(s) that helped you to solve the issue...
          Keep code clean.

          1 Reply Last reply
          7

          • Login

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