可通过样式表来设置按钮的外观。
ui->buttonCheck->setStyleSheet(
//正常状态样式
"QPushButton{"
"background-color:#67a6f8;"//设置按钮背景色
"border-radius:5px;"//设置圆角半径
"color:white;"//设置按钮字体颜色
"}"
//鼠标悬停样式
"QPushButton:hover{"
"background-color:#5f9ae6;"
"color:white;"
"}");
这是为某一个特定的按钮设置样式,如果希望为所有的按钮设置相同的样式,可将第一行代码做修改。
setStyleSheet(
//正常状态样式
"QPushButton{"
"background-color:#67a6f8;")
"border-radius:5px;"
"color:white;"
"}"
//鼠标悬停样式
"QPushButton:hover{"
"background-color:#5f9ae6;"
"color:white;"
"}");
效果如下: