Re: Using QBrush(const QGradient & gradient) constructor causes a problem
I'm trying to draw an image like the radial gradient one in the Qt gradients example, working with:
Qt 5.0.1 (64 bit) Qt Creator 2.6.2
on a Mac with OS X 10.8.3 (Mountain Lion)
It gives an memory access error and points to the line where the brush is constructed, whether brush is a pointer or not.
Code:
ballItem::ballItem()
{
// brush = new QBrush(gradient);
}
This is the header:
Code:
#include <QGraphicsItem>
{
public:
ballItem();
protected:
private:
};
I was trying to use this QBrush constructor:
QBrush::QBrush(const QGradient & gradient)
I would appreciate it if somebody can show me my error.
Added after 40 minutes:
It seems that QConicalGradient, QLinearGradient or QRadialGradient needs to be used, not QGradient, because the QGradient type isn't initialized.
http://lists.trolltech.com/qt-jambi-...ad00025-0.html
Re: Using QBrush(const QGradient & gradient) constructor causes a problem
So is your problem solved or not?
Re: Using QBrush(const QGradient & gradient) constructor causes a problem
The "Elastic Nodes Example" provided me with a simpler way to draw a ball with a light spot and a smooth transition to the darker parts.
In that example - Node:: paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) - QRadialGradient is used:
My problem is solved, and I think to use QRadialGradient would also work to draw an image like the one in the "Gradients" example. Interestingly though, I see in that example - in void GradientRenderer::paint(QPainter *p) - a QGradient variable is declared and used:
Code:
void GradientRenderer
:: paint(QPainter *p
) {
// and then farther down in the function:
p->setBrush(g);
When I tried to do the same, it crashed, because I left out this part:
Code:
if (m_gradientType == Qt::LinearGradientPattern) {
} else if (m_gradientType == Qt::RadialGradientPattern) {
} else {
QLineF l
(pts.
at(0), pts.
at(1));
qreal angle
= l.
angle(QLineF(0,
0,
1,
0));
if (l.dy() > 0)
angle = 360 - angle;
}
g is changed to a QLinearGradient or a QRadialGradient or a QConicalGradient.