图片开关新增选中切换信号

master
feiyangqingyun 2022-04-28 08:35:52 +08:00
parent 50d4e9ab0a
commit 936387b210
4 changed files with 19 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include "frmimageswitch.h"
#include "ui_frmimageswitch.h"
#include "qdebug.h"
frmImageSwitch::frmImageSwitch(QWidget *parent) : QWidget(parent), ui(new Ui::frmImageSwitch)
{
@ -19,10 +20,22 @@ void frmImageSwitch::initForm()
ui->imageSwitch1->setChecked(true);
ui->imageSwitch2->setChecked(true);
ui->imageSwitch3->setChecked(true);
ui->imageSwitch1->setFixedSize(87, 30);
ui->imageSwitch2->setFixedSize(87, 30);
ui->imageSwitch3->setFixedSize(87, 30);
ui->imageSwitch1->setButtonStyle(ImageSwitch::ButtonStyle_1);
ui->imageSwitch2->setButtonStyle(ImageSwitch::ButtonStyle_2);
ui->imageSwitch3->setButtonStyle(ImageSwitch::ButtonStyle_3);
//绑定选中切换信号
connect(ui->imageSwitch1, SIGNAL(checkedChanged(bool)), this, SLOT(checkedChanged(bool)));
connect(ui->imageSwitch2, SIGNAL(checkedChanged(bool)), this, SLOT(checkedChanged(bool)));
connect(ui->imageSwitch3, SIGNAL(checkedChanged(bool)), this, SLOT(checkedChanged(bool)));
}
void frmImageSwitch::checkedChanged(bool checked)
{
qDebug() << sender() << checked;
}

View File

@ -20,6 +20,7 @@ private:
private slots:
void initForm();
void checkedChanged(bool checked);
};
#endif // FRMIMAGESWITCH_H

View File

@ -18,6 +18,7 @@ void ImageSwitch::mousePressEvent(QMouseEvent *)
{
imgFile = isChecked ? imgOffFile : imgOnFile;
isChecked = !isChecked;
emit checkedChanged(isChecked);
this->update();
}

View File

@ -46,6 +46,7 @@ private:
public:
bool getChecked() const;
ButtonStyle getButtonStyle() const;
QSize sizeHint() const;
QSize minimumSizeHint() const;
@ -54,6 +55,9 @@ public Q_SLOTS:
void setChecked(bool isChecked);
//设置按钮样式
void setButtonStyle(const ImageSwitch::ButtonStyle &buttonStyle);
Q_SIGNALS:
void checkedChanged(bool checked);
};
#endif // IMAGESWITCH_H