左侧用 QToolButton 组, 右侧用 QStackedWidget,信号槽绑定切换页面
可定制化高
QButtonGroup* btnGp = new QButtonGroup(this);btnGp->addButton(ui->btn1, 0);btnGp->addButton(ui->btn2, 1);btnGp->addButton(ui->btn3, 2);connect(btnGp, QOverload<int>::of(&QButtonGroup::idClicked), ui->stackedWidget, &QStackedWidget::setCurrentIndex);// 默认页面btnGp->button(0)->setChecked(true);ui->stackedWidget->setCurrentIndex(0);// 设置样式ui->tab->setStyleSheet(R"(
QToolButton{border: 1 1 1 1;min-width: 80px;min-height: 40px;
}
QToolButton::hover{font:13pt bold;}
QToolButton::pressed,QToolButton::checked{background-color: lightblue;font-size:15pt;border-left: 7px inset darkCyan;
}
QStackedWidget > QToolButton{background-color:none
})"); // border: dashed dotted solid double; outset inset groove ridge