diff --git a/day12/qtdemo3/main.cpp b/day12/qtdemo3/main.cpp new file mode 100755 index 0000000..c3efeb4 --- /dev/null +++ b/day12/qtdemo3/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/day12/qtdemo3/qtdemo3.pro b/day12/qtdemo3/qtdemo3.pro new file mode 100755 index 0000000..632f97a --- /dev/null +++ b/day12/qtdemo3/qtdemo3.pro @@ -0,0 +1,34 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +FORMS += \ + widget.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + res.qrc diff --git a/day12/qtdemo3/res.qrc b/day12/qtdemo3/res.qrc new file mode 100755 index 0000000..744a169 --- /dev/null +++ b/day12/qtdemo3/res.qrc @@ -0,0 +1,10 @@ + + + resources/add.png + resources/mario.gif + resources/open.png + resources/save.png + resources/Sunny.jpg + + + diff --git a/day12/qtdemo3/resources/Sunny.jpg b/day12/qtdemo3/resources/Sunny.jpg new file mode 100755 index 0000000..1eea0c4 Binary files /dev/null and b/day12/qtdemo3/resources/Sunny.jpg differ diff --git a/day12/qtdemo3/resources/add.png b/day12/qtdemo3/resources/add.png new file mode 100755 index 0000000..8c41538 Binary files /dev/null and b/day12/qtdemo3/resources/add.png differ diff --git a/day12/qtdemo3/resources/mario.gif b/day12/qtdemo3/resources/mario.gif new file mode 100755 index 0000000..c38a831 Binary files /dev/null and b/day12/qtdemo3/resources/mario.gif differ diff --git a/day12/qtdemo3/resources/open.png b/day12/qtdemo3/resources/open.png new file mode 100755 index 0000000..1282b1e Binary files /dev/null and b/day12/qtdemo3/resources/open.png differ diff --git a/day12/qtdemo3/resources/save.png b/day12/qtdemo3/resources/save.png new file mode 100755 index 0000000..4e33bd4 Binary files /dev/null and b/day12/qtdemo3/resources/save.png differ diff --git a/day12/qtdemo3/widget.cpp b/day12/qtdemo3/widget.cpp new file mode 100755 index 0000000..37c8612 --- /dev/null +++ b/day12/qtdemo3/widget.cpp @@ -0,0 +1,99 @@ +#include "widget.h" +#include "ui_widget.h" +#include + + +Widget::Widget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::Widget) +{ + n=0; + ui->setupUi(this); + + // 设置 imageLable 的图片资源 + QPixmap pixmap; + // : 开头表示引用 Qt 的资源文件 + pixmap.load(":/images/mario"); // 加载像素图 + ui->imageLable->resize(200,200); + ui->imageLable->setPixmap(pixmap); // 设置 QLable 显示图片 + + marioGif = new QMovie(":/images/mario"); + ui->imageLable->setMovie(marioGif); + +} + +Widget::~Widget() +{ + delete ui; +} + + +void Widget::on_hotBtn_clicked() +{ + ui->whatLable->setText("巧乐兹"); +} + +void Widget::on_coldBtn_clicked() +{ + ui->whatLable->setText("厚棉被"); +} + +void Widget::on_coldBtn_2_clicked() +{ + +} + +void Widget::on_setTitleIconBtn_clicked() +{ + n++; + if(n%2==0){ + + this->setWindowIcon(QIcon(":/images/save")); + this->setWindowTitle("标题被修改了"); + showMaximized(); + } else{ + this->setWindowIcon(QIcon("")); + this->setWindowTitle(""); + showNormal(); + } +} + +void Widget::on_showImg_pressed() +{ + //ui->imageLable->hide(); + marioGif->start(); +} + +void Widget::on_showImg_released() +{ + marioGif->stop(); + //ui->imageLable->show(); +} + +void Widget::on_setImgBtn_pressed() +{ + QPixmap pixmap2; + pixmap2.load(":/images/sunny"); + + ui->showImg->setText(""); + ui->showImg->setIconSize(QSize(200,200)); + ui->showImg->setIcon(pixmap2); +} + +void Widget::on_setImgBtn_released() +{ + ui->showImg->setText("图片运输中"); + ui->showImg->setIcon(QPixmap()); +} + +void Widget::on_setbgBtn_clicked() +{ +// setStyleSheet("background-color: red; color: white; font-size: 16px;"); + //setStyleSheet("background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0 #FF0000, stop:0.17 #FF7F00, stop:0.33 #FFFF00, stop:0.5 #00FF00, stop:0.67 #0000FF, stop:0.83 #4B0082, stop:1 #8B00FF);"); + //QString styleSheet = "background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:0.5 #000000, stop:0 #FF00F0,stop:1 #0F0F0F);"; + //setStyleSheet(styleSheet); + showFullScreen(); + + +} + diff --git a/day12/qtdemo3/widget.h b/day12/qtdemo3/widget.h new file mode 100755 index 0000000..c036e5e --- /dev/null +++ b/day12/qtdemo3/widget.h @@ -0,0 +1,49 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class Widget; } +QT_END_NAMESPACE + +class Widget : public QWidget +{ + Q_OBJECT + +private: + int n; + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); + +private slots: + void on_hotBtn_clicked(); + + void on_coldBtn_clicked(); + + void on_coldBtn_2_clicked(); + + void on_setTitleIconBtn_clicked(); + + void on_setImgBtn_clicked(); + + void on_showImg_pressed(); + + void on_showImg_released(); + + void on_setImgBtn_pressed(); + + void on_setImgBtn_released(); + + void on_setbgBtn_clicked(bool checked); + + void on_setbgBtn_clicked(); + +private: + Ui::Widget *ui; + QMovie *marioGif; +}; +#endif // WIDGET_H diff --git a/day12/qtdemo3/widget.ui b/day12/qtdemo3/widget.ui new file mode 100755 index 0000000..e3c6563 --- /dev/null +++ b/day12/qtdemo3/widget.ui @@ -0,0 +1,216 @@ + + + Widget + + + + 0 + 0 + 654 + 476 + + + + OpenHandCursor + + + Widget + + + + :/images/open:/images/open + + + + + 170 + 8 + 201 + 81 + + + + ClosedHandCursor + + + font: 36pt "华文隶书"; +alternate-background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(9, 41, 4, 255), stop:0.085 rgba(2, 79, 0, 255), stop:0.19 rgba(50, 147, 22, 255), stop:0.275 rgba(236, 191, 49, 255), stop:0.39 rgba(243, 61, 34, 255), stop:0.555 rgba(135, 81, 60, 255), stop:0.667 rgba(121, 75, 255, 255), stop:0.825 rgba(164, 255, 244, 255), stop:0.885 rgba(104, 222, 71, 255), stop:1 rgba(93, 128, 0, 255)); +color: rgb(255, 85, 255); + + + 热了 + + + + 37 + 55 + + + + + + + 10 + 110 + 191 + 69 + + + + WhatsThisCursor + + + background-color: rgb(0, 170, 255); +font: 18pt "华文琥珀"; + + + 出门买啥? + + + + + + 230 + 120 + 361 + 141 + + + + SizeBDiagCursor + + + Qt::RightToLeft + + + background-color: rgb(255, 85, 0); +color: rgb(255, 255, 255); +background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 0, 0, 255), stop:0.166 rgba(255, 255, 0, 255), stop:0.333 rgba(0, 255, 0, 255), stop:0.5 rgba(0, 255, 255, 255), stop:0.666 rgba(0, 0, 255, 255), stop:0.833 rgba(255, 0, 255, 255), stop:1 rgba(255, 0, 0, 255)); +font: 72pt "华文彩云"; + + + + + + + + + 410 + 10 + 201 + 81 + + + + CrossCursor + + + font: 36pt "华文隶书"; +selection-background-color: rgb(255, 170, 127); +color: rgb(170, 255, 255); + + + 冻着了 + + + + + true + + + + 20 + 260 + 121 + 121 + + + + WaitCursor + + + + + + + + + 240 + 300 + 191 + 49 + + + + SizeHorCursor + + + font: 28pt "华文隶书"; + + + + 设置图片 + + + + + + 240 + 400 + 191 + 49 + + + + UpArrowCursor + + + font: 18pt "华文隶书"; + + + + 标题Icon修改 + + + + + + 440 + 280 + 201 + 181 + + + + ForbiddenCursor + + + 图片正在派送中 + + + + + + 20 + 40 + 141 + 49 + + + + UpArrowCursor + + + font: 18pt "华文隶书"; + + + + 背景修改 + + + + + + + + diff --git a/day12/qtdemo4/main.cpp b/day12/qtdemo4/main.cpp new file mode 100755 index 0000000..c3efeb4 --- /dev/null +++ b/day12/qtdemo4/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/day12/qtdemo4/qtdemo4.pro b/day12/qtdemo4/qtdemo4.pro new file mode 100755 index 0000000..632f97a --- /dev/null +++ b/day12/qtdemo4/qtdemo4.pro @@ -0,0 +1,34 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +FORMS += \ + widget.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + res.qrc diff --git a/day12/qtdemo4/res.qrc b/day12/qtdemo4/res.qrc new file mode 100755 index 0000000..44fa5b0 --- /dev/null +++ b/day12/qtdemo4/res.qrc @@ -0,0 +1,5 @@ + + + resources/yanhua1.gif + + diff --git a/day12/qtdemo4/resources/yanhua1.gif b/day12/qtdemo4/resources/yanhua1.gif new file mode 100755 index 0000000..e9b4bf5 Binary files /dev/null and b/day12/qtdemo4/resources/yanhua1.gif differ diff --git a/day12/qtdemo4/widget.cpp b/day12/qtdemo4/widget.cpp new file mode 100755 index 0000000..f282f57 --- /dev/null +++ b/day12/qtdemo4/widget.cpp @@ -0,0 +1,47 @@ +#include "widget.h" +#include "ui_widget.h" + + +Widget::Widget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::Widget) +{ + ui->setupUi(this); + + // 加载动画资源 + yanhuagif = new QMovie(":/movies/yanhua"); + + srand(time(NULL)); + randNum = rand() % 10; // 0-9的数 + + // 开启定时器, 用于定时换随机数 + timer = new QTimer(); + connect(timer,&QTimer::timeout,[&](){ + randNum = rand() % 10; + }); + timer->start(5*1000); // 5秒 + + +} + +Widget::~Widget() +{ + delete ui; +} + + +void Widget::on_pushButton_clicked() +{ + guessNum = ui->numEdit->text().toInt(); + qDebug() << "随机数:" << randNum << "输入的数" << guessNum << endl; + QString resStr = "随机数: "+ QString::number(randNum)+ ", 你输入的数: "+QString::number(guessNum); + ui->tipesLable->setText("本轮结果: " + resStr); + if(guessNum == randNum){ + ui->resaultShowLabel->setMovie(yanhuagif); + yanhuagif->start(); + } else { + if(yanhuagif->state() == QMovie::Running) + yanhuagif->stop(); + ui->resaultShowLabel->setText(" "); + } +} diff --git a/day12/qtdemo4/widget.h b/day12/qtdemo4/widget.h new file mode 100755 index 0000000..066de23 --- /dev/null +++ b/day12/qtdemo4/widget.h @@ -0,0 +1,32 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class Widget; } +QT_END_NAMESPACE + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); + +private slots: + void on_pushButton_clicked(); + +private: + Ui::Widget *ui; + int guessNum = 0; + int randNum = 0; + QMovie *yanhuagif; + QTimer *timer; +}; +#endif // WIDGET_H diff --git a/day12/qtdemo4/widget.ui b/day12/qtdemo4/widget.ui new file mode 100755 index 0000000..a5d7d3b --- /dev/null +++ b/day12/qtdemo4/widget.ui @@ -0,0 +1,133 @@ + + + Widget + + + + 0 + 0 + 500 + 400 + + + + Widget + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + padding:5px; +font: 18pt "Agency FB"; + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + font: 18pt "Agency FB"; + + + 猜一猜 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Horizontal + + + + + + + + + + font: 14pt "宋体"; +color: rgb(170, 170, 255); + + + 结果: + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +