From 293a8d9c40d686397829c5d415fc531b6956883e Mon Sep 17 00:00:00 2001 From: feiyangqingyun Date: Thu, 28 Apr 2022 08:36:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E7=89=87=E5=BC=80=E5=85=B3=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=80=89=E4=B8=AD=E5=88=87=E6=8D=A2=E4=BF=A1=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/imageswitch/frmimageswitch.cpp | 13 +++++++++++++ control/imageswitch/frmimageswitch.h | 1 + control/imageswitch/imageswitch.cpp | 1 + control/imageswitch/imageswitch.h | 4 ++++ 4 files changed, 19 insertions(+) diff --git a/control/imageswitch/frmimageswitch.cpp b/control/imageswitch/frmimageswitch.cpp index b0548cd..c9eb586 100644 --- a/control/imageswitch/frmimageswitch.cpp +++ b/control/imageswitch/frmimageswitch.cpp @@ -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; } diff --git a/control/imageswitch/frmimageswitch.h b/control/imageswitch/frmimageswitch.h index 7f0e243..c6e087a 100644 --- a/control/imageswitch/frmimageswitch.h +++ b/control/imageswitch/frmimageswitch.h @@ -20,6 +20,7 @@ private: private slots: void initForm(); + void checkedChanged(bool checked); }; #endif // FRMIMAGESWITCH_H diff --git a/control/imageswitch/imageswitch.cpp b/control/imageswitch/imageswitch.cpp index c8eec65..87a6fa5 100644 --- a/control/imageswitch/imageswitch.cpp +++ b/control/imageswitch/imageswitch.cpp @@ -18,6 +18,7 @@ void ImageSwitch::mousePressEvent(QMouseEvent *) { imgFile = isChecked ? imgOffFile : imgOnFile; isChecked = !isChecked; + emit checkedChanged(isChecked); this->update(); } diff --git a/control/imageswitch/imageswitch.h b/control/imageswitch/imageswitch.h index 385641d..1bbf060 100644 --- a/control/imageswitch/imageswitch.h +++ b/control/imageswitch/imageswitch.h @@ -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