开效果:
关效果:
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->checkBox->setText("");
ui->checkBox->setFixedSize(128, 64);
QString qss = "QCheckBox::indicator:unchecked{ \
image:url(:/resources/status_close.png); \
} \
QCheckBox::indicator:checked { \
image: url(:/resources/status_open.png); \
}";
ui->checkBox->setStyleSheet(qss);
ui->checkBox->setChecked(false);
connect(ui->checkBox, &QCheckBox::stateChanged, this, &MainWindow::slot_stateChanged);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slot_stateChanged(int state)
{
if(ui->checkBox->isChecked())
{
ui->lineEdit->setText("open");
}
else
{
ui->lineEdit->setText("close");
}
}
效果: