CSSQWidget[width="50"]{ …}
C++ (Qt)class MyStyledWidget : public QWidget{ Q_OBJECT ...}
C++ (Qt)#include <QApplication>#include <QGridLayout>#include <QPushButton> int main( int argc, char** argv ){ QApplication app( argc, argv ); QWidget w; w.setStyleSheet( ".QWidget { background-color: cyan }" ); QGridLayout gl( &w ); for( int i = 0; i < 3; i++ ) for( int j = 0; j < 3; j++ ) { QPushButton* pb = new QPushButton( QString( "%1:%2" ).arg( i ).arg( j ) ); gl.addWidget( pb, i, j ); } w.show(); return app.exec();}
C++ (Qt)QString QWIDGET_GRAY = "собственно css без селекторов";SetCSS( w, QSSBlack::QWIDGET_GRAY );
C++ (Qt)void SetCSS( QWidget* widget, QString css ){ widget->setStyleSheet( "#" + widget->objectName() + " {" + css + "}";}
C++ (Qt)void SetCSS( QWidget* widget, QString css ){ if ( widget->objectName().isEmpty() ) { widget->setObjectName( QString::number( (size_t)widget, 16 ) ); } widget->setStyleSheet( "#" + widget->objectName() + " {" + css + "}";}