[Qt-interest] having trouble creating custom Q_PROPERTY for use with stylesheets
Robert Douglas
rwdougla at gmail.com
Thu Jul 22 03:45:45 CEST 2010
I've been banging my head against a wall for this, and am hoping someone
out there can help me out. Any help is appreciated.
I have 2 files as such:
File : MyObj.h
#ifndef MY_OBJ_H
#define MY_OBJ_H
#include <QtCore/QObject>
class MyObj : public QObject
{
Q_OBJECT
Q_PROPERTY(int theInt READ getInt WRITE setInt DESIGNABLE true)
public:
int getInt() const { return x; }
void setInt(int val)
{
x = val;
}
private:
int x;
};
#endif
File main.cpp:
#include <QtGui/QApplication>
#include <QtGui/QPushButton>
#include <QtCore/QVariant>
#include "MyObj.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setStyleSheet("MyObj { qproperty-theInt: 5 }");
MyObj mo;
//mo.setProperty("theInt", 5);
QPushButton pb;
pb.show();
return a.exec();
}
I don't get any errors in the application's output, and the debugger
never gets to setInt(int). If I uncomment the "setProperty" line, that
hits the setInt function just fine. Thus, I am sure the property system
knows of the property, I just can't figure out how to get the stylesheet
system to use it.
Any thoughts?
Thanks in advance,
-Rob
More information about the Qt-interest-old
mailing list