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. Change colour of specific item in Qwt Plot
Qt 6.11 is out! See what's new in the release blog

Change colour of specific item in Qwt Plot

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 495 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.
  • A Offline
    A Offline
    AhmedAlshawi
    wrote on last edited by
    #1

    Hi All,

    I have developed a qwt that contains multiple QwtPlotShapeItems.

    //Run a function to get an array of polygons
    QVector<QPolygonF> polygonArray;
    createPolygonArray(lines, polygonArray, maxdistance);
    
    //add each polygon in the polygon array to the qwt plot
    for (int j = 0; j < polygonArray.size(); j = j + 1)
    {
        QwtPlotShapeItem *shape = new QwtPlotShapeItem;
        shape->setPen(QColor(0,0,0), Qt::SolidLine);
        shape->setTitle("shapeNumber_" + QString::number(j));
        shape->setBrush(QColor(130,130,130,50));
        shape->setPolygon(polygonArray[j]);
        shape->attach(&myPlot);
        V.push_back(shape);
    }
    myPlot.replot();
    

    I want to return to my plot at a later point in my code and loop through all the attached QwtPlotShapeItems, and if it's title matches what I looking for, then I want to change the colour of that shape. So for example:

    //.....later on in my code, in another function that the plot is passed into (by ref)
    for (int j = 0; j < myPlot.numberOfAttachedShapeItems(); j = j + 1)
    {
        if (myPlot.attachedShapeItem[j].Title() == "shapeNumber_7")
        {
            myPlot.attachedShapeItem[j].setBrush(QColor(0,0,0,255));
        }
    }
    

    Is this possible, or do I have to recreate my plot each time I want to change the color of a single shapeItem?

    Thank you!

    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