需要按钮盒子两个按钮不同样式,现有两个一个OK、一个cancel两个按钮,需要吧ok变成蓝色,cancel变成灰色怎么设置
QDialogButtonBox {
button {
background-color: blue;
}
button:disabled {
background-color: gray;
}
}
给俩种按钮设置俩个objectname,在样式表中通过objectname分别来设置
// 获取到按钮对象
QPushButton *okButton = buttonBox.button(QDialogButtonBox::Ok);
QPushButton *cancelButton = buttonBox.button(QDialogButtonBox::Cancel);
// 设置按钮的样式
okButton->setStyleSheet("QPushButton { background-color: green; color: white; }");
cancelButton->setStyleSheet("QPushButton { background-color: red; color: white; }");