PDA

View Full Version : No CSS in child class



kartun
2nd February 2011, 10:01
I've my widget "MeasurePanel" inherited from QWidget:

class MeasurePanel : public QWidget
{
Q_OBJECT
Q_PROPERTY (int value READ value WRITE setValue)
Q_PROPERTY (QColor fontColor READ fontColor WRITE setFontColor)


public:
explicit MeasurePanel(QWidget *parent = 0);
...


At design time I added CSS to it (and it's displayed correctly @ designer):

QWidget#MeasurePanel{
border-width: 3px;
border-style: inset;
border-color: #000000;
border-radius: 9px;

background-color: qlineargradient(spread:pad, x1:0.5, y1:1, x2:0.5, y2:0, stop:0 rgba(116, 38, 116, 255), stop:0.99115 rgba(239, 0, 239, 255));
}

In main application I've :


MeasurePanel* panels[4];
...
panels[0] = new MeasurePanel(this);

//panels[0]->setObjectName("MeasurePanel");

qDebug() << panels[0]->objectName();
// panels[0]->setStyleSheet("MeasurePanel#MeasurePanel{border-width: 3px; border-style: inset; border-color: #000000; border-radius: 9px;}");
ui->gridLayout->addWidget(panels[0],1,0);


But after this CSS isn't displayed. I checked ObjectName (commented), and it's "MeasurePanel". I've tried CSS in different forms:

QWidget#MeasurePanel
QWidget > MeasurePanel
MeasurePanel#MeasurePanel

But still can't get it working.


Addition :
tried this one :

panels[0]->setProperty("MeasurePanel", true);
panels[0]->setStyleSheet("*[MeasurePanel=\"true\"]{border-width: 3px; border-style: inset; border-color: #000000;}");


Same thing.

Another addition:
I put everything inside QFrame and now I'm able to edit that frame CSS, but still can't modify Widget CSS.