C++ 如何为应用程序中的某些按钮重置QApplication::样式表?
在main()函数中,我在应用程序的所有按钮上设置样式表C++ 如何为应用程序中的某些按钮重置QApplication::样式表?,c++,qt,qt5,qtstylesheets,C++,Qt,Qt5,Qtstylesheets,在main()函数中,我在应用程序的所有按钮上设置样式表 qApp->setStyleSheet("QPushButton {" " border: 1px solid #8f8f91;" " border-radius: 4px;" " background-color: qlineargradie
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;"
" }");
但是现在我需要重置一些按钮的样式。我尝试了按钮->设置样式表(“”
),但它不起作用。那么,如何做到这一点呢?你不能
您可以做的恰恰相反,即设置某些按钮的样式表,如下所示:
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
的按钮才具有自定义外观,其他按钮看起来正常。您不能
您可以做的恰恰相反,即设置某些按钮的样式表,如下所示:
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
的按钮才具有自定义外观,其他按钮看起来正常