Equivalent of GDIPlus::PathGradientBrush
Unsolved
General and Desktop
-
In Microsoft GDIPlus I might have this code:
Graphics graphics(hdc);// structure Graphics object Pen m_pen(Color::Blue,2); SolidBrush m_Brush(Color::Green); Point points[] = { Point(30, 30), Point(180, 30), Point(180, 150), Point(30, 150) }; PathGradientBrush pathBrush(points,4);// Use points to create brushes pathBrush.SetCenterColor(Color::Red);// Set center color Color colors[] = { Color::Green ,Color::Black,Color::Yellow,Color::Blue}; int count = 4; pathBrush.SetSurroundColors(colors, &count);// Set the border color graphics.FillRectangle(&pathBrush, 30, 30, 150, 120);
which would result in this:
How do I do that using Qt? I looked at QConicalGradient, but I couldn't see how I might use it to get that result :(
Note that in my case I'm dealing with triangles not squares.
Thanks
David -
I don't think there's a built in gradient type in Qt that can do that in one pass. The best would be to create your own gradient type I think, but if you're ok with a multi-pass approach you could blend multiple linear gradients like this:
QRect r(0,0,200,200); QPainter p(some_paint_device); p.fillRect(r, Qt::red); QLinearGradient g(r.topLeft(), r.center()); g.setColorAt(0,Qt::green); g.setColorAt(1,Qt::transparent); p.fillRect(r, g); g.setStart(r.topRight()); g.setColorAt(0,Qt::black); p.fillRect(r, g); g.setStart(r.bottomRight()); g.setColorAt(0,Qt::yellow); p.fillRect(r, g); g.setStart(r.bottomLeft()); g.setColorAt(0,Qt::blue); p.fillRect(r, g);
Obviously not a great solution if you have a lot of triangles to fill like that.