当前位置:网站首页>Day16QtQLabel2021-10-22

Day16QtQLabel2021-10-22

2022-06-22 02:44:00 Morning and evening rain

QLabel Use

QLabel Generally used to display text and pictures , Can pass Qt The designer interface sets related properties , For example, set the text to be displayed in the middle ; You can set the font ; Can be used to display pictures and text , Let's make a small scene , Cover the above functions .

Use QLabel According to the text 、 picture 、 Moving graph

Clear... Has been described in the relevant configuration code , Post code directly

.cpp In the code

#include "mylabel.h"
#include "ui_mylabel.h"
#include <QPixmap>
#include <QMovie>
myLabel::myLabel(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::myLabel)
{
    
    ui->setupUi(this);

    // by Label Add border 
    ui->textLab->setFrameShape(QFrame::Box);
    // Set the font 
    QFont font;
    font.setFamily(" Chinese Xingkai ");// typeface 
    font.setPointSize(20);// size 
    font.setBold(true);// In bold 
// font.setItalic(true);// Italics 
    ui->textLab->setFont(font);
    ui->textLab->setText("Day15, perseverance prevails !");

    // Use QLabel display picture 
    QPixmap pix(":/res/Day15.png");
// pix = pix.scaled(300,300);
     ui->picLab->setScaledContents(true);// Set the playback content size to be adjustable , The same function as the previous comment statement 
    ui->picLab->setPixmap(pix);

    // Use QLabel Show dynamic diagram 
    QMovie *movie = new QMovie(":res/action.gif");
// movie->resized(QSize(300,300));
    ui->movieLab->setScaledContents(true);
    ui->movieLab->setMovie(movie);
    movie->start();
}
myLabel::~myLabel()
{
    
    delete ui;
}


.h In the code

#ifndef MYLABEL_H
#define MYLABEL_H

#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui {
     class myLabel; }
QT_END_NAMESPACE
class myLabel : public QWidget
{
    
    Q_OBJECT
public:
    myLabel(QWidget *parent = nullptr);
    ~myLabel();
private:
    Ui::myLabel *ui;
};
#endif // MYLABEL_H

effect

 Insert picture description here

原网站

版权声明
本文为[Morning and evening rain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211658130079.html