Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Stylesheets with derived classes

Tags:

c++

qt

qt4

qwidget

Can I use Qt stylesheets with a derived widget? I'd like to be able to define some custom properties on the widget (like various colors) and be able to define their value in a stylesheet.

Is this possible?

like image 918
Mike Avatar asked Feb 02 '26 04:02

Mike


1 Answers

Sure, just declare your properties with Q_PROPERTY.

class MyClass : public QObject
{
    Q_OBJECT
    Q_PROPERTY( int fun READ getFun WRITE setFun )
    public:
    MyClass( QObject * parent=0, const char * name=0 );
    ~MyClass();

    void setFun( int x );
    int getFun() const;
};
like image 187
bitc Avatar answered Feb 03 '26 18:02

bitc