diff --git a/DialogTest/widget.cpp b/DialogTest/widget.cpp index 7350ff4..2f382b8 100644 --- a/DialogTest/widget.cpp +++ b/DialogTest/widget.cpp @@ -1,8 +1,23 @@ #include "widget.h" +#include +#include +#include Widget::Widget(QWidget *parent) : QWidget(parent) { + this->resize(600,400); + button = new QPushButton("选择文件",this); + button->resize(100,100); + button->move(250,100); + + connect(button,&QPushButton::clicked,[](){ +// QString str = QFileDialog::getOpenFileName(); +// qDebug()< +#include class Widget : public QWidget { Q_OBJECT +private: + QPushButton *button; + public: Widget(QWidget *parent = nullptr); ~Widget(); diff --git a/EventTest/main.cpp b/EventTest/main.cpp index fd3e533..5d03a7b 100644 --- a/EventTest/main.cpp +++ b/EventTest/main.cpp @@ -1,11 +1,38 @@ #include "mainwindow.h" #include +#include +#include + +class EventLabel : public QLabel +{ +protected: + void mouseMoveEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); +}; + +void EventLabel::mouseMoveEvent(QMouseEvent *event){ + this->setText(QString("

Move: (%1, %2)

").arg(QString::number(event->x()),QString::number(event->y))); +} + +void EventLabel::mousePressEvent(QMouseEvent *event){ + this->setText(QString("

Press: (%1, %2)

").arg(QString::number(event->x()),QString::number(event->y))); +} + +void EventLabel::mouseReleaseEvent(QMouseEvent *event){ + QString msg; + msg.sprintf("

Release: (%d, %d)

", event->x(), event->y()); +} int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; - w.show(); + + EventLabel *label = new EventLabel; + label->setWindowTitle("MouseEvent Demo"); + label->resize(300,200); + label->show(); + return a.exec(); } diff --git a/homework-day1/main.cpp b/homework-day1/main.cpp index 78725e7..0fb5fce 100644 --- a/homework-day1/main.cpp +++ b/homework-day1/main.cpp @@ -12,25 +12,26 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - // Widget7 w; - // w.show(); - Widget7 judge1; - Widget7 judge2; - Widget7 judge3; +// Widget7 w; +// w.show(); - Widget8 w8; + Widget7 judge1; + Widget7 judge2; + Widget7 judge3; - judge1.show(); - judge2.show(); - judge3.show(); + Widget8 w8; - // 建立信号槽连接 - w8.connect(&judge1,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection); - w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection); - w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection); + judge1.show(); + judge2.show(); + judge3.show(); + + // 建立信号槽连接 + w8.connect(&judge1,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection); + w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection); + w8.connect(&judge2,&Widget7::studentSelected,&w8,&Widget8::receviceStudentSelection); -// w8.show(); +// w8.show(); return a.exec(); } diff --git a/homework-day1/widget5.cpp b/homework-day1/widget5.cpp index fae87ba..f56a3ed 100644 --- a/homework-day1/widget5.cpp +++ b/homework-day1/widget5.cpp @@ -21,6 +21,4 @@ Widget5::Widget5(QWidget *parent) : QWidget(parent) this->setWindowTitle("Winget6消失了"); w6->close(); }); - - } diff --git a/homework-day1/widget5.h b/homework-day1/widget5.h index ffd653c..f1b38a5 100644 --- a/homework-day1/widget5.h +++ b/homework-day1/widget5.h @@ -11,6 +11,7 @@ class Widget5 : public QWidget Q_OBJECT public: explicit Widget5(QWidget *parent = nullptr); + ~Widget5(){ delete w6;} private: Widget6 *w6; // Widget6 类对象的指针成员 diff --git a/homework-day1/widget7.cpp b/homework-day1/widget7.cpp index 83b0379..32147e0 100644 --- a/homework-day1/widget7.cpp +++ b/homework-day1/widget7.cpp @@ -24,37 +24,42 @@ Widget7::Widget7(QWidget *parent) : QWidget(parent) btn_restart = new QPushButton("重新再来",this); btn_restart->move(150,70); - connect(this,&Widget7::my_signal,this,&Widget7::my_handler); - + // connect(this,&Widget7::my_signal,this,&Widget7::my_handler); + connect(this,SIGNAL(my_signal(const QString &)),this,SLOT(my_handler(const QString &))); connect(btn1,&QPushButton::clicked,[&]{ QString str = btn1->text(); emit this->my_signal(str); emit this->studentSelected(str); + btn1->setEnabled(false); }); connect(btn2,&QPushButton::clicked,[&]{ QString str = btn2->text(); emit this->my_signal(str); emit this->studentSelected(str); + btn2->setEnabled(false); }); connect(btn3,&QPushButton::clicked,[&]{ QString str = btn3->text(); emit this->my_signal(str); emit this->studentSelected(str); + btn3->setEnabled(false); }); connect(btn4,&QPushButton::clicked,[&]{ QString str = btn4->text(); emit this->my_signal(str); emit this->studentSelected(str); + btn4->setEnabled(false); }); connect(btn5,&QPushButton::clicked,[&]{ QString str = btn5->text(); emit this->my_signal(str); emit this->studentSelected(str); + btn5->setEnabled(false); }); // 打印学生 @@ -64,16 +69,24 @@ Widget7::Widget7(QWidget *parent) : QWidget(parent) qDebug()<<*it; it++; } +// for(int i=0;isize();i++){ +// qDebug()<at(i); +// } }); connect(btn_restart,&QPushButton::clicked,[&]()->void{ vct->clear(); // 清空容器 + btn1->setEnabled(true); // 还原按钮可用性 + btn2->setEnabled(true); + btn3->setEnabled(true); + btn4->setEnabled(true); + btn5->setEnabled(true); }); } void Widget7::my_handler(const QString &str) { - // qDebug()<append(str); // 向 QVector 中添加学生 + if(vct->count(str) == 0) // 当本字符串尚未加入 vct 时,将其加入 vct + vct->append(str); // 向 QVector 中添加学生 } diff --git a/homework-day1/widget7.h b/homework-day1/widget7.h index 1753ce8..f5d97b7 100644 --- a/homework-day1/widget7.h +++ b/homework-day1/widget7.h @@ -10,10 +10,8 @@ class Widget7 : public QWidget Q_OBJECT public: explicit Widget7(QWidget *parent = nullptr); - ~Widget7() - { - delete vct; - } + ~Widget7() { delete vct; } + private: QVector *vct; QPushButton *btn1,*btn2,*btn3,*btn4,*btn5; diff --git a/西安IoT2301-刘博-Qt第2天-作业.zip b/西安IoT2301-刘博-Qt第2天-作业.zip new file mode 100644 index 0000000..a4d9d43 Binary files /dev/null and b/西安IoT2301-刘博-Qt第2天-作业.zip differ