This commit is contained in:
parent
4f2d4f5d87
commit
3aad444cdf
|
@ -1,8 +1,23 @@
|
|||
#include "widget.h"
|
||||
#include <QFileDialog>
|
||||
#include <QString>
|
||||
#include <QDebug>
|
||||
|
||||
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()<<str;
|
||||
QStringList str = QFileDialog::getOpenFileNames();
|
||||
qDebug()<<str;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
|
|
|
@ -2,11 +2,15 @@
|
|||
#define WIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
class Widget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QPushButton *button;
|
||||
|
||||
public:
|
||||
Widget(QWidget *parent = nullptr);
|
||||
~Widget();
|
||||
|
|
|
@ -1,11 +1,38 @@
|
|||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
|
||||
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("<center><h1>Move: (%1, %2)</h1></center>").arg(QString::number(event->x()),QString::number(event->y)));
|
||||
}
|
||||
|
||||
void EventLabel::mousePressEvent(QMouseEvent *event){
|
||||
this->setText(QString("<center><h1>Press: (%1, %2)</h1></center>").arg(QString::number(event->x()),QString::number(event->y)));
|
||||
}
|
||||
|
||||
void EventLabel::mouseReleaseEvent(QMouseEvent *event){
|
||||
QString msg;
|
||||
msg.sprintf("<center><h1>Release: (%d, %d)</h1></center>", 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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,4 @@ Widget5::Widget5(QWidget *parent) : QWidget(parent)
|
|||
this->setWindowTitle("Winget6消失了");
|
||||
w6->close();
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ class Widget5 : public QWidget
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit Widget5(QWidget *parent = nullptr);
|
||||
~Widget5(){ delete w6;}
|
||||
|
||||
private:
|
||||
Widget6 *w6; // Widget6 类对象的指针成员
|
||||
|
|
|
@ -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;i<vct->size();i++){
|
||||
// qDebug()<<vct->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()<<str;
|
||||
vct->append(str); // 向 QVector 中添加学生
|
||||
if(vct->count(str) == 0) // 当本字符串尚未加入 vct 时,将其加入 vct
|
||||
vct->append(str); // 向 QVector 中添加学生
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@ class Widget7 : public QWidget
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit Widget7(QWidget *parent = nullptr);
|
||||
~Widget7()
|
||||
{
|
||||
delete vct;
|
||||
}
|
||||
~Widget7() { delete vct; }
|
||||
|
||||
private:
|
||||
QVector<QString> *vct;
|
||||
QPushButton *btn1,*btn2,*btn3,*btn4,*btn5;
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue