思路:QPushButton继承于QWidget,可以将其看做一个QWidget,在其上放置一个Qlabel进行布局即可。
QPushButton* btn = new QPushButton(this);
// 设置label为红色圆形
QLabel* lab = new QLabel(btn,"123");
const QString label_style =
"min-width:40px;min-height:40px;max-width:40px;max-height:40px;border-radius:20px;border:1px solid black;background:red";color:white;
lab->setStyleSheet(label_style);
//然后采用布局将其放置在button上即可
QHBoxLayout*lay = new QHBoxLayout(btn);
//具体位置可以自行调整,这里仅加入布局
lay->addWidget(lab);
btn->setLayout(lay);
其他背景颜色
//background:green //blue // yellow