[Qt-interest] Setting custom properties with style sheets.
Roland Labrecque
roland at ics.com
Sun Jul 19 17:38:27 CEST 2009
I would like to set custom properties from a style sheet. I can
successfully query a custom property but can't set it. Is this even
possible?
I've included an example below which defines a property "columns" on
LineEditField.
My style sheet looks like:
LineEditField[columns="10"] { background-color: green; } /* This Works:
ie the background on all LineEdits with the "column" property are green */
LineEditField#le2 { columns: 15; } /* This doesn't do anything and
reports an error on the command line "Unknown property columns" */
Do I have the syntax wrong or is this just not possible.
Cheers,
Roland
Example Code:
>>----------------------------------------------------------------------------------------------------
#include <QtGui>
#include <QDebug>
class LineEditField : public QLineEdit
{
Q_OBJECT
Q_PROPERTY(int columns
READ get_columns
WRITE set_columns
STORED true)
public:
LineEditField(QWidget * p=0) : QLineEdit(p) {set_columns(0);}
int get_columns() { return m_c; }
public slots:
void set_columns(int c)
{
m_c=c;
setText(QString().setNum(m_c));
qDebug() << "set_columns(" << c << ")";
}
private:
int m_c;
};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
LineEditField* le1 = new LineEditField;
le1->setObjectName("le1");
le1->setProperty("columns",QVariant(10));
LineEditField* le2 = new LineEditField;
le2->setObjectName("le2");
le2->setProperty("columns",QVariant(20));
QVBoxLayout* vl = new QVBoxLayout;
vl->addWidget(le1);
vl->addWidget(le2);
QWidget* w= new QWidget;
w->setLayout(vl);
a.setStyleSheet(
"LineEditField[columns=\"10\"] { background-color: green; }"
"LineEditField#le2 { columns: 15; }"
);
w->show();
a.exec();
}
#include "main.moc
More information about the Qt-interest-old
mailing list