#include #include #include #include #include int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles); QApplication a(argc,argv); QMainWindow mw; mw.setGeometry(50,50,600,400); mw.setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); a.setStyleSheet("QMainWindow { color: red }"); QLabel *l = new QLabel("Test", &mw); mw.show(); QObject::connect(&mw, &QWidget::customContextMenuRequested, l, [&mw, l] (const QPoint&) { delete l; QLabel *ll = new QLabel("Test 2", &mw); ll->show(); // workaround to force palette propagation: // ll->setStyleSheet("background-color: blue"); // ll->setStyleSheet(""); }); return a.exec(); }