1.widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QMovie>
#include <QPushButton>
#include <QFont>
#include <QLayout>
#include <QVBoxLayout>
class MyMainWindow : public QWidget
{
Q_OBJECT
public:
MyMainWindow(QWidget *parent = 0);
MyMainWindow(char *);
QMovie movie;
~MyMainWindow();
public slots:
void UnPause();
void Pause();
void addSpeed();
void decSpeed();
void quit();
private:
unsigned long num;
QLabel *label;
QPushButton *b1;
QPushButton *b2;
QPushButton *b3;
QPushButton *b4;
QPushButton *b5;
};
#endif // WIDGET_H
2.widget.cpp
#include "widget.h"
MyMainWindow::MyMainWindow(QWidget *parent)
: QWidget(parent)
{
}
MyMainWindow::MyMainWindow(char *str1):movie(str1)
{
setGeometry(100,100,300,280);
num=100;
b1=new QPushButton("Continue!",this);
b1->setMaximumSize(90,30);
b1->setFont(QFont("Times",18,QFont::Bold));
b2=new QPushButton("Pause!",this);
b2->setMaximumSize(90,30);
b2->setFont(QFont("Times",18,QFont::Bold));
b3=new QPushButton("Hurry!",this);
b3->setMaximumSize(90,30);
b3->setFont(QFont("Times",18,QFont::Bold));
b4=new QPushButton("Slow!",this);
b4->setMaximumSize(90,30);
b4->setFont(QFont("Times",18,QFont::Bold));
b5=new QPushButton("Quit!",this);
b5->setMaximumSize(90,30);
b5->setFont(QFont("Times",18,QFont::Bold));
label=new QLabel(this);
label->setMovie(&movie);
movie.start();
QVBoxLayout *vbox=new QVBoxLayout(this);
vbox->addWidget(label);
vbox->addWidget(b1);
vbox->addWidget(b2);
vbox->addWidget(b3);
vbox->addWidget(b4);
vbox->addWidget(b5);
connect(b1,SIGNAL(clicked()),this,SLOT(UnPause()));
connect(b2,SIGNAL(clicked()),this,SLOT(Pause()));
connect(b3,SIGNAL(clicked()),this,SLOT(addSpeed()));
connect(b4,SIGNAL(clicked()),this,SLOT(decSpeed()));
connect(b5,SIGNAL(clicked()),this,SLOT(quit()));
}
MyMainWindow::~MyMainWindow()
{
}
void MyMainWindow::UnPause()
{
movie.start();
}
void MyMainWindow::Pause()
{
movie.stop();
}
void MyMainWindow::addSpeed()
{
num+=20;
movie.setSpeed(num);
}
void MyMainWindow::decSpeed()
{
num-=20;
movie.setSpeed(num);
}
void MyMainWindow::quit()
{
exit(0);
}