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. LineChart: one line with different colors
Qt 6.11 is out! See what's new in the release blog

LineChart: one line with different colors

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 748 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.
  • R Offline
    R Offline
    rguardia
    wrote on last edited by
    #1

    Hello,

    I want to plot a LineChart using diffrent colors for the same QLineSeries. I have been searching but I found nothing. Does anyone know if this is possible with Qt?

    I attach a photo to show what I would like to do.

    Thanks
    0_1497268880238_upload-1f78228f-b720-4e66-9906-2efe36073bbd

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rguardia
      wrote on last edited by
      #2

      I found a kind of solution to do this using gradients. It is probably not the best way but by now it accomplishes the goal.

      QLinearGradient gradient(0,0,0,1);
      gradient.setColorAt(0, Qt::blue);
      gradient.setColorAt(threshold_low-0.1, Qt::blue);
      gradient.setColorAt(threshold_low, Qt::gray);
      gradient.setColorAt(threshold_up, Qt::gray);
      gradient.setColorAt(threshold_up+0.1, Qt::red);
      gradient.setColorAt(1, Qt::red);
      gradient.setCoordinateMode(QGradient::StretchToDeviceMode);
      QPen pen(QBrush(gradient), 2);
      
      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