A method called "className()" is available for the widgets through the meta object. In my scenario, it looks like this:
slider.metaObject()->className();
// ==> mimas::Slider
Since the "Slider" class is within a namespace, you need to use the fully qualified name when styling (replace '::' with '--'):
mimas--Slider { background-color:blue; }
Another approach is to define a class property and apply it using a leading dot:
.slider { background-color:blue; }
In the C++ Slider class:
Q_PROPERTY(QString class READ cssClass)
...
QString cssClass() { return QString("slider"); }
On the topic of drawing the slider with colors and styles defined in CSS, here's how you can access them (link text):
// background-color:
palette.color(QPalette::Window)
// color:
palette.color(QPalette::WindowText)
// border-width:
// not possible (unfortunately...). To make it work, you would have to manually retrieve QRenderRule class headers from qstylesheetstyle.cpp,
// get the private headers from QStyleSheetStyle, modify them to access renderRule function, and then obtain the border width data.
// But this approach may lead to linking issues due to local symbol visibility in QtGui.
// The recommended solution is to utilize properties instead:
// qproperty-border:
border_width_ // or any variable holding the Q_PROPERTY border
Lastly, some notes on QPalette values mapping to CSS equivalents:
color = QPalette::WindowText
background = QPalette::Window
alternate-background-color = QPalette::AlternateBase
selection-background-color = QPalette::Highlighted
selection-color = QPalette::HighlightedText