tag:blogger.com,1999:blog-27901662.post8516021519253045050..comments2024-03-28T07:30:33.361+00:00Comments on Zack Rusin: Gradient boundsZackhttp://www.blogger.com/profile/16222054590923441165noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-27901662.post-77069712027618591442007-03-09T09:00:00.000+00:002007-03-09T09:00:00.000+00:00Yes, that should work fine.Yes, that should work fine.Zackhttps://www.blogger.com/profile/16222054590923441165noreply@blogger.comtag:blogger.com,1999:blog-27901662.post-28705421523456293562007-03-08T15:37:00.000+00:002007-03-08T15:37:00.000+00:00Ok, I could of have explained myself better.I was ...Ok, I could of have explained myself better.<BR/><BR/>I was only wondering if it was possible the following.<BR/><BR/>In logical coordinate space:<BR/>QPainter p(this);<BR/>QLinearGradient gradient(70, 10, 70, 70);<BR/>p.setBrush(gradient);<BR/>p.drawRect(40,40,100,100);<BR/><BR/>and so the ObjectBox equivalent:<BR/><BR/>QPainter p(this);<BR/>QLinearGradient gradient(0.5, -0.5, 0.5, 0.5);<BR/>gradient.setCoordinateMode(QGradient::ObjectBoundingMode);<BR/>p.setBrush(gradient);<BR/>p.drawRect(...any coordinates...);<BR/><BR/><BR/>Here is an SVG file as an example, using a radial gradient, which may make more evident the use case of such gradients that have the focal point outside of the object's bounding box.<BR/><BR/>http://www.ricardmarxer.com/outgradient.svgRicard Marxerhttps://www.blogger.com/profile/09603585880374897046noreply@blogger.comtag:blogger.com,1999:blog-27901662.post-49733565992878338472007-03-08T08:54:00.000+00:002007-03-08T08:54:00.000+00:00Just love those little changes that make life easi...Just love those little changes that make life easier. Thank you.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-27901662.post-77461210333166511992007-03-08T06:56:00.000+00:002007-03-08T06:56:00.000+00:00Hey, no that's not what it means. Here's how you d...Hey, no that's not what it means. Here's how you draw gradients in logical mode:<BR/>QPainter p(this);<BR/>QLinearGradient gradient(40, 40, 100, 100);<BR/>p.setBrush(gradient);<BR/>p.drawRect(40, 40, 100, 100);<BR/>As you can see the coordinates for the gradient have to match the coordinates of the shape that the gradient is filling. Now imagine lots of rendering calls - we'd have to create a separate gradient for each and every one of those (it also implies you know before the bounding boxes of every shape to be rendered). With object bounding box mode you do:<BR/>QPainter p(this);<BR/>QLinearGradient gradient(0, 0, 1, 1);<BR/>gradient.setCoordinateMode(QGradient::ObjectBoundingMode);<BR/>p.setBrush(gradient);<BR/>p.drawRect(...any coordinates...);<BR/>Now the QLinearGradient coordinates will be mapped to the shape it's being rendered on. (0, 0) means top-left, (1, 1) means bottom-right, and anything in between is the interpolation of those.Zackhttps://www.blogger.com/profile/16222054590923441165noreply@blogger.comtag:blogger.com,1999:blog-27901662.post-23604951639930909632007-03-07T22:47:00.000+00:002007-03-07T22:47:00.000+00:00ups... sorry for being anonymous the las time.I st...ups... sorry for being anonymous the las time.<BR/><BR/>I still think that the same way you can define a stop inside the bounding box with a value from 0 to 1 it can be interesting to define the stops outside the bounding box of the shape, so that the gradient doesn't actually stop at one of the defined colors but rather at an interpolation point between two stops, of course the gradient shouldn't show outside the shape.Ricard Marxerhttps://www.blogger.com/profile/09603585880374897046noreply@blogger.comtag:blogger.com,1999:blog-27901662.post-85768953323495217332007-03-07T22:15:00.000+00:002007-03-07T22:15:00.000+00:00Anomymous, those are the gradient stops. When it c...Anomymous, those are the gradient stops. When it comes time to paint the gradient, the rectangle has to be defined in raw coordinates. And if you don't coordinate-match the two, you can wind up drawing your gradient effectively at a negative or over 1 stop, so all you get is a solid color. Its terribly inconvenient. This, as I understand it, allows you to define a gradient and have it auto-stretch to the area being painted.b10663rhttps://www.blogger.com/profile/08073995943287353986noreply@blogger.comtag:blogger.com,1999:blog-27901662.post-89662128062965002852007-03-07T21:53:00.000+00:002007-03-07T21:53:00.000+00:00Maybe I'm missing something, but why are the coord...Maybe I'm missing something, but why are the coordinates for gradients bounded from 0 to 1 in the ObjectBoundingMode?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-27901662.post-30618022981472000562007-03-07T18:04:00.000+00:002007-03-07T18:04:00.000+00:00This is Huge. I assume it applies to resizing boun...This is Huge. I assume it applies to resizing bounds for the widget, and not just the top,left starting position?<BR/><BR/>How do you control the z-order so your selection isn't over written by the gradients behind?b10663rhttps://www.blogger.com/profile/08073995943287353986noreply@blogger.com