-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
110 lines (89 loc) · 2.66 KB
/
Copy pathmainwindow.cpp
File metadata and controls
110 lines (89 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPushButton>
#include <QCloseEvent>
#include <QMessageBox>
#include <QString>
#include <QWidget>
#include "shutdown.h"
#include <QMediaPlayer>
#include <QSound>
#include <QMovie>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//重置窗口大小
resize(800,600);
//固定窗口大小
this->setFixedSize(800,600);
//设置标题
// this->setWindowTitle("peppa");
//设置窗口标题
this->setWindowTitle(QString("peppa"));
this->setWindowTitle("pappe");
//初始化对象
ShutDown *Msd = new ShutDown;
//添加音乐
QSound *bgm = new QSound("F:/C++Pritice/QThomework/05_File/cry/BGM~1.wav",this);
bgm->setLoops(-1);
bgm->play();
ui->setupUi(this);
//ui->centralWidget->setMouseTracking(true);
this->setMouseTracking(true);
count = 1;
//创建一个按钮,功能为关闭窗口
QPushButton *myBtn = new QPushButton;
myBtn->show();
myBtn->setParent(this);
myBtn->setText("不是");
myBtn->move(400,400);//设置按钮坐标
//myBtn->setGeometry(60,60,50,50);
connect(myBtn,&QPushButton::clicked,[=](){
QMessageBox::critical(this,"错误","回答错误,请重新选择!");
});
//创建一个按钮
QPushButton *btn = new QPushButton;
btn->show();
btn->setParent(this);
btn->setText("是");
btn->move(100,400);
connect(btn,&QPushButton::clicked,[=](){
if(QMessageBox::critical(this,"恭喜","你选择了正确答案!")== QMessageBox::Ok)
{
if(QMessageBox::critical(this,"警告","你的电脑将于1分钟以后关机!请保存数据!")==QMessageBox::Ok)
{
Msd->MySystemShutdownOrRestart();
qDebug()<<"调用成功!";
}
}
});
//给label_2添加动图
QMovie * movie = new QMovie("F:/C++Pritice/QThomework/05_File/cry/timg.gif");
ui->label_2->setMovie(movie);
movie->start();
ui->label_2->show();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::mouseMoveEvent(QMouseEvent *p)
{
qDebug()<<count++;
qDebug()<<p;
qDebug()<<p->pos().x()<<","<<p->pos().y();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
//取消X的关闭功能
if(QMessageBox::information(this,"略略略",QStringLiteral("关不掉我!"),QMessageBox::Ok,QMessageBox::NoButton)== QMessageBox::Ok)
{
event->ignore();
}
else
{
event->accept();
}
}