您可以尝试从QCheckBox继承并绘制您想要的内容。查看此示例自定义push_button(向按钮上的文本添加阴影)。
#include "CustomButton.h"
#include
#include
#include
CustomButton::CustomButton(QWidget *parent):
QPushButton(parent)
{
}
void CustomButton::paintEvent(QPaintEvent *event)
{
QStylePainter p(this);
QFontMetrics font = this->fontMetrics();
QRect textRect = font.boundingRect(text());
int x = rect().center().x()-textRect.center().x();
int y = rect().center().y()-textRect.center().y();
++y;
p.drawControl(QStyle::CE_PushButton, getStyleOption()); //draw button with stylesheet
QStyleOptionButton opt = getStyleOption();
opt.text = text();
QPen tempPen = p.pen();
p.setPen(Qt::white);
p.drawText(x, y, text()); //draw text shadow on the button