<Linux+Qt>在Widget中使用qlabel显示图片与动画


#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();

}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Client</class> <widget class="QDialog" name="Client"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>396</width> <height>196</height> </rect> </property> <property name="windowTitle"> <string>Dialog</string> </property> <widget class="QPushButton" name="cCancleBtn"> <property name="geometry"> <rect> <x>180</x> <y>150</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>取消</string> </property> </widget> <widget class="QPushButton" name="cCloseBtn"> <property name="geometry"> <rect> <x>280</x> <y>150</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>关闭</string> </property> </widget> <widget class="QLabel" name="cStatusLbl"> <property name="geometry"> <rect> <x>60</x> <y>110</y> <width>131</width> <height>16</height> </rect> </property> <property name="text"> <string>等待接收文件...</string> </property> </widget> <widget class="QLabel" name="label_2"> <property name="geometry"> <rect> <x>60</x> <y>60</y> <width>54</width> <height>12</height> </rect> </property> <property name="text"> <string>已完成</string> </property> </widget> <widget class="QProgressBar" name="progressBar"> <property name="geometry"> <rect> <x>110</x> <y>50</y> <width>271</width> <height>23</height> </rect> </property> <property name="value"> <number>0</number> </property> </widget> </widget> <resources/> <connections/> </ui>紧扣该段代码,介绍其界面的设计基本原则
06-10

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值