初学qt,点击按钮添加选中颜色,其他按钮还原颜色,代码:
void Widget::On_PushButton1Result()
{
//按钮1槽函数
stackLayout->setCurrentIndex(0); //切换到stackLayout第一页
ui->pushButton->setStyleSheet("background-color: rgb(35, 39, 46);color: rgb(255, 255, 255);");
ui->pushButton_2->setStyleSheet("background-color: rgb(16, 17, 20);color: rgb(154, 160, 177);");
ui->pushButton_3->setStyleSheet("background-color: rgb(16, 17, 20);color: rgb(154, 160, 177);");
//m_pageOne->show();//show hide 也可实现
// widget置于上层
// ui->widget->raise();
}
void Widget::On_PushButton2Result()
{
//按钮2槽函数
stackLayout->setCurrentIndex(1); //切换到stackLayout第二页
ui->pushButton->setStyleSheet("background-color: rgb(16, 17, 20);color: rgb(154, 160, 177);");
ui->pushButton_2->setStyleSheet("background-color: rgb(35, 39, 46);color: rgb(255, 255, 255);"