Custom colors from style sheet

  • I was wondering how or if I could get colors for custom items from a style sheet.

    For example I have a graph widget with 5 curves and I want the color of each curve to be customizable via the style sheet of the application.



  • Moderators

    just define styleable properties in your QWidget class and use the properties for painting:
    class MyGraphWidget : public QWidget
    Q_PROPERTY( QColor CurveColor READ ... WRITE ... DESIGNABLE true );


      //getter and setter for properties


    and in the stylesheet you can simply do this then:
    qproperty-CurveColor: #00FF00;
    /* or */
    qproperty-CurveColor: red;

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.