#include <QWidget>
#include <QGridLayout>
namespace Ui {
class ViewForm;
}
class ViewForm : public QWidget
{
Q_OBJECT
public:
explicit ViewForm(QWidget *parent = 0);
~ViewForm();
private slots:
void on_pushbutton_clicked();
private:
Ui::ViewForm *ui;
// QWidget *sub ;
QMovie *movie;
bool moviestatus;
};
#include "ui_viewform.h"
#include <QGridLayout.h>
#include<QLabel>
#include<QPixmap>
#include<QMovie>
#include<QPushButton>
ViewForm::ViewForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::ViewForm)
{
ui->setupUi(this);
movie =new QMovie("E:/Codes/QtTest/images/hiahia.gif");
moviestatus = false;
ui->label->setMovie(movie);
ui->label->show();
ui->pushbutton->setText("开始,嘿嘿");
}
ViewForm::~ViewForm()
{
delete ui;
}
void ViewForm::on_pushbutton_clicked()
{
if(!moviestatus)
{
ui->pushbutton->setText("歇会,呼呼");
movie->start();
moviestatus = true;
}
else
{
ui->pushbutton->setText("继续,嘻嘻");
moviestatus = false;
movie->stop();
}
}
以上为子框架ViewForm.h与ViewForm.cpp的代码
下面为运行进入主框架代码:
Mainform.h代码
#ifndef MAINFORM_H
#define MAINFORM_H
#include <QWidget>
#include<QtGui>
#include<QGridLayout>
#include "viewform.h"
class MainForm : public QWidget
{
Q_OBJECT
public:
explicit MainForm(QWidget *parent = 0);
~MainForm();
private:
ViewForm* viewWidget;
private slots:
void viewChange();
};
#endif // MAINFORM_H
MainForm.cpp的代码
#include "mainform.h"
MainForm::MainForm(QWidget *parent) :
QWidget(parent)
{
QPushButton * view = new QPushButton("视频切换");
QGridLayout * glout = new QGridLayout;
this->setGeometry(QRect(0,0,400,300));
QDesktopWidget* desktop = QApplication::desktop(); // =qApp->desktop();也可以
move((desktop->width() - this->width())/2, (desktop->height() - this->height())/2);
// glout->setGeometry(QRect(10,10,10,10));
glout->addWidget(view);
connect(view,SIGNAL(clicked()),this,SLOT(viewChange()));
setLayout(glout);
}
MainForm::~MainForm()
{
}
void MainForm::viewChange()
{
viewWidget = new ViewForm;
viewWidget->setWindowTitle("视频");
viewWidget->show();
}