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