PDA

View Full Version : Passing QLinearGradient as Property from QSS



droneone
21st January 2013, 18:24
Hi all,

I'm having a bit of an issue and I'm hoping one of you can help to shed some light on what I'm doing wrong.

What I'm trying to do: pass a QLinearGradient as a custom property to a class from QSS. I'm able to pass many other data types as QProperties via QSS without issue.

What happens: the set method is never called even when the property is set via the QSS.

For example, I do this:




#include <QFrame>
#include <QColor>
#include <QLinearGradient>
#include <QDebug>

namespace Ui {
class Foo;
}

Q_DECLARE_METATYPE(QLinearGradient)

class Foo : Public QFrame {

Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor DESIGNABLE true)
Q_PROPERTY(QLinearGradient fillColor READ fillColor WRITE setFillColor DESIGNABLE true)

public:

explicit Foo(QWidget* parent);
~Foo();

QColor color();
void setColor(QColor p_color);

QLinearGradient fillColor();
void setFillColor(QLinearGradient p_grad);

};


and in the .cpp file, for example:




#include "foo.h"
#include "ui_foo.h"

Foo:Foo(QWidget *parent) : QFrame(parent), ui(new Ui::Foo) {

// handle QGradient metatype registration for our property
qRegisterMetaType<QLinearGradient>("QLinearGradient");
ui->setupUi(this);
}

Foo:~Foo() {

delete ui;
}

QColor Foo::color() {
return QColor;
}

void Foo::setColor(QColor p_color) {
qDebug() << "Got Color Change";
}


QLinearGradient Foo::fillColor() {
return QLinearGradient;
}

void Foo::setFillColor(QLinearGradient p_grad) {
qDebug() << "Got new QGradient";

}


And, the qss (loaded from a file):



Foo {
qproperty-color: rgb(77, 154, 205);
qproperty-fillColor: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(77, 154, 205, 255), stop:1 rgba(255, 255, 255, 175));
}


Which results in a debugging message showing setColor() is called, but no message indicates setFillColor() was called. EDIT: I forgot to note, the read method -does- get called.

Is there something I'm failing to do to pass a QLinearGradient properly? I know I can pass the two colors in the gradient without issue, as individual properties, but I want the QSS to be able to control the spread, etc. without a lot of qproperty- settings. (And all of the requisite code).

Thanks!