Results 1 to 4 of 4

Thread: Trouble: Updating color QColor and QBrush

  1. #1
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Trouble: Updating color QColor and QBrush

    I am trying to visualize a calculation by drawing ellipses with QPainter.drawEllipse. Initially all ellipses have the same color but after the calculations the ellipses should have different colors according to the result. But the color never changes, below is an example of code:

    void CoordPlot:: paintEvent(QPaintEvent *e)
    {
    QPainter painter(this);
    painter.setWindow(-800000,-100000,900000,900000);

    painter.scale(1.0,1.0);
    painter.rotate(90.0);

    QColor c1(255,0,0,255);
    QBrush b1(c1);
    painter.setBrush(b1);

    //just a test to draw an ellipse and a rectangle, works fine
    painter.drawEllipse(x,y,5000,5000);
    painter.drawRect(a,b,5000,5000);

    //plot the dataset, does not work ok, the color is never changed!
    int s=0;
    for(unsigned int i=0; i<dataset.size(); i++){
    //Set the RGB alpha value to c1 from the dataset

    c1.setRgb(dataset[i].r,dataset[i].g,dataset[i].b,255);
    painter.setBrush(b1);

    painter.drawEllipse(dataset[i].y,dataset[i].x,6000,6000);
    }

    }

    Pseudo code:
    calculate and update RGB values in the dataset[]
    repaint();
    the colors are not changing...
    Any hint?

    Regards
    Pete

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble: Updating color QColor and QBrush

    If you copied correctly, you’re never updating the brush to the new color:
    Qt Code:
    1. c1.setRgb(dataset[i].r,dataset[i].g,dataset[i].b,255);
    2. b1.setColor(c1); /* missing in your code */
    3. painter.setBrush(b1);
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble: Updating color QColor and QBrush

    You are correct i copied the code incorrectly:
    "b1.setColor(c1); /* missing in your code */"

    But it is still not working...

    what could be wrong?

  4. #4
    Join Date
    Oct 2009
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Trouble: Updating color QColor and QBrush

    Ok!

    It works now, the error was in the loop that does the actual calculations. It was incorrectly updating the colors with invalid RGB values!

    thank you anyway for the help

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.