闹钟文章来源:https://www.toymoban.com/news/detail-563922.html
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QDebug>
#include <QIcon>
#include <QLabel>
#include <QTextEdit>
#include <QPushButton>
#include <QLineEdit>
#include <QPainter>
#include <QKeyEvent>
#include <QMessageBox>
#include <QFont>
#include <QFontDialog>
#include <QTimerEvent>
#include <QMediaPlayer>
#include <QAudioOutput>
#include <QVideoWidget>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
QVideoWidget *vw;
QAudioOutput *audioOutput;
QMediaPlayer *player;
explicit Widget(QWidget *parent = nullptr);
~Widget();
void timerEvent(QTimerEvent *e) override;
private:
Ui::Widget *ui;
bool flag=false;
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"
#include "QFile"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
audioOutput = new QAudioOutput(this);
player = new QMediaPlayer(this);
vw = new QVideoWidget(this);
vw->resize(160,240);
vw->move(180,40);
player->setAudioOutput(audioOutput);
player->setVideoOutput(vw);
player->setSource(QUrl("https://v2rf4u4qumepw2enhu6m5ploy41qnho6k.free-lbv3.idouyinvod.com/v3-web.douyinvod.com/b834889b01459b5303a7d0871ca9cb73/64ac298a/video/tos/cn/tos-cn-ve-15c001-alinc2/aedc7f073a904b4abb89df52b4e2df85/?a=6383&ch=26&cr=0&dr=0&lr=all&cd=0%7C0%7C0%7C0&br=1127&bt=1127&cs=0&ds=3&ft=GN7rKGVVywf-RFm8Zmo~xj7ScoAp6c1-6vrKq3iZH2o0g3&mime_type=video_mp4&qs=0&rc=aTtnODw0ZmU0OzppPDVpM0BpajZmeDQ6ZnZqPDMzNGkzM0AuLjEuNjE0NjYxMy5gYDYwYSNmXjNycjRvcWxgLS1kLS9zcw%3D%3D&l=20230710225246BBB4D7031D20A71DF5F9&btag=e00028000&ali_redirect_ex_hot=66666800&ali_redirect_ex_beacon=1"));
audioOutput->setVolume(50);
startTimer(1000);
this->setWindowTitle("闹钟");
this->setWindowIcon(QIcon(":/icon/pineapple.png"));
ui->timeEdit->setDisplayFormat("HH:mm:ss");
ui->timeEdit->setTime(QTime::currentTime());
ui->timeEdit->setAlignment(Qt::AlignCenter);
ui->lineEdit->setAlignment(Qt::AlignCenter);
ui->lineEdit->setFont(QFont("Arial", 18));
ui->lineEdit->setStyleSheet("QLineEdit {"
"border: none;"
"background: transparent;"
"}");
connect(ui->pushButton,&QPushButton::clicked,[=](){this->flag=true;});
connect(ui->pushButton_2,&QPushButton::clicked,[=](){this->flag=false;});
}
Widget::~Widget()
{
delete ui;
}
void Widget::timerEvent(QTimerEvent *e)
{
e->timerId();
QDateTime sys_dt = QDateTime::currentDateTime();
ui->lineEdit->setText(sys_dt.toString("hh:mm:ss"));
QTime timeEditTime = ui->timeEdit->time();
QTime lineEditTime = sys_dt.time();
if(this->flag&&timeEditTime.second() == lineEditTime.second() &&timeEditTime.minute() == lineEditTime.minute() &&timeEditTime.hour() == lineEditTime.hour()){
player->play();
QMessageBox::information(this,"闹钟","快起来,你个懒猪!");
}
}
文章来源地址https://www.toymoban.com/news/detail-563922.html
到了这里,关于7.10 qt作业的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!