在我的 main() 函数中,我在应用程序的所有按钮上设置样式表。
qApp->setStyleSheet("QPushButton {"
" border: 1px solid #8f8f91;"
" border-radius: 4px;"
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #dadbde);"
" padding: 3px;"
" }");
但是现在我需要重新设置一些按钮的样式。我试过 button->setStyleSheet("")
,但它不起作用。那么,该怎么做呢?
最佳答案
你不能。
您可以做相反的事情,即为某些按钮设置样式表,如下所示:
qApp->setStyleSheet("QPushButton[specialButton=\"true\"] {"
" border: 1px solid #8f8f91;"
" border-radius: 4px;"
" background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #f6f7fa, stop: 1 #dadbde);"
" padding: 3px;"
"}");
然后:
button->setProperty("specialButton", true);
这样只有 specialButton 设置为 true
的按钮才会有自定义外观,其他按钮看起来正常。
关于c++ - 如何为应用程序中的某些按钮重置 QApplication::styleSheet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51723304/