Results 1 to 1 of 1

Thread: Passing QLinearGradient as Property from QSS

  1. #1
    Join Date
    Dec 2011
    Posts
    27
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Passing QLinearGradient as Property from QSS

    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:

    Qt Code:
    1. #include <QFrame>
    2. #include <QColor>
    3. #include <QLinearGradient>
    4. #include <QDebug>
    5.  
    6. namespace Ui {
    7. class Foo;
    8. }
    9.  
    10. Q_DECLARE_METATYPE(QLinearGradient)
    11.  
    12. class Foo : Public QFrame {
    13.  
    14. Q_OBJECT
    15. Q_PROPERTY(QColor color READ color WRITE setColor DESIGNABLE true)
    16. Q_PROPERTY(QLinearGradient fillColor READ fillColor WRITE setFillColor DESIGNABLE true)
    17.  
    18. public:
    19.  
    20. explicit Foo(QWidget* parent);
    21. ~Foo();
    22.  
    23. QColor color();
    24. void setColor(QColor p_color);
    25.  
    26. QLinearGradient fillColor();
    27. void setFillColor(QLinearGradient p_grad);
    28.  
    29. };
    To copy to clipboard, switch view to plain text mode 

    and in the .cpp file, for example:

    Qt Code:
    1. #include "foo.h"
    2. #include "ui_foo.h"
    3.  
    4. Foo:Foo(QWidget *parent) : QFrame(parent), ui(new Ui::Foo) {
    5.  
    6. // handle QGradient metatype registration for our property
    7. qRegisterMetaType<QLinearGradient>("QLinearGradient");
    8. ui->setupUi(this);
    9. }
    10.  
    11. Foo:~Foo() {
    12.  
    13. delete ui;
    14. }
    15.  
    16. QColor Foo::color() {
    17. return QColor;
    18. }
    19.  
    20. void Foo::setColor(QColor p_color) {
    21. qDebug() << "Got Color Change";
    22. }
    23.  
    24.  
    25. QLinearGradient Foo::fillColor() {
    26. }
    27.  
    28. void Foo::setFillColor(QLinearGradient p_grad) {
    29. qDebug() << "Got new QGradient";
    30.  
    31. }
    To copy to clipboard, switch view to plain text mode 

    And, the qss (loaded from a file):

    Qt Code:
    1. Foo {
    2. qproperty-color: rgb(77, 154, 205);
    3. 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));
    4. }
    To copy to clipboard, switch view to plain text mode 

    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!
    Last edited by droneone; 21st January 2013 at 17:54.

Similar Threads

  1. QLinearGradient Coloring
    By WSQtProgrammer in forum Qt Programming
    Replies: 1
    Last Post: 5th July 2012, 17:59
  2. QAbstractItemDelegate and QLinearGradient
    By toutarrive in forum Qt Programming
    Replies: 2
    Last Post: 12th February 2010, 17:20
  3. Regarding qlineargradient
    By jjbabu in forum Qt Programming
    Replies: 6
    Last Post: 15th April 2009, 09:21
  4. Related QLinearGradient
    By ashishsaryar in forum Qt Programming
    Replies: 5
    Last Post: 26th May 2008, 10:09
  5. QLinearGradient question
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 7th March 2008, 16:52

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.