QWidget :: SetStyleSheet () core code principle:
This function will be executed during execution:
void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate)
{
。。。
/*
You can see that it will find all widgets and perform drawing
*/
if (propagate) {
// We copy the list because the order may be modified
const QObjectList childrenList = children;
for (int i = 0; i < childrenList.size(); ++i) {
QWidget *c = qobject_cast<QWidget*>(childrenList.at(i));
if (c)
c->d_func()->inheritStyle();
}
}
。。。
}
We generally think so, but some widgets that seem to be not widgets will also take effect, such as:
QListView::itemr {
background-color: rgb(110,110,110);
color:rgb(233,233,233);
}
The item of QListView is QAbstractWidgetItem, it is not a widget, but it can perform drawing, because the underlying core code of QListView, its interface Item is indeed QAbstractWidgetItem, it is indeed not an item, but the bottom layer of QListView should be similar to there is a layer of widget, It is used to associate with QAbstractWidgetItem and display the data of the item. Therefore, the item set in the stylesheet is not a QAbstractWidgetItem that looks similar, but a corresponding widget at the bottom of the association is this item.