(八)控件介绍,QLable

 

 

Radio单选框

默认互斥,加GroupBox进行分组可以解决这个

checkBox复选

 

ListWidget

TableWIdget:有表头

#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
#include <QDebug>
#include <QMovie>

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    connect(ui->radioButton, &QRadioButton::released, this, [=]()
    {
        QMessageBox::information(this, "radiobutton", "haha+++");
    });

    connect(ui->checkBox, &QCheckBox::stateChanged, this, [=](int state)
    {
        //QMessageBox::information(this, "checkbox", QString::number(state));
        qDebug() << state;
    });

    ui->listWidget->addItem("hello, 软件园!");
    QListWidgetItem* item = new QListWidgetItem(QIcon("D:\\Luffy.png"), "Luffy", ui->listWidget);
    ui->listWidget->addItem(new QListWidgetItem(QIcon("D:\\Luffy.png"), "luffy"));

    // 1. 指定行数
    ui->tableWidget->setRowCount(100);
    // 2. 指定列数
    ui->tableWidget->setColumnCount(3);
    QStringList list;
    list << "姓名" << "性别" << "年龄";
    ui->tableWidget->setHorizontalHeaderLabels(list);

    ui->tableWidget->setItem(0,0,new QTableWidgetItem(QIcon(":/Image/face.png"),"haha"));
    ui->tableWidget->setItem(0,1,new QTableWidgetItem(QIcon(":/Image/face.png"),"haha"));
    ui->tableWidget->setItem(0,2,new QTableWidgetItem(QIcon(":/Image/face.png"),"haha"));

    ui->tableWidget->setItem(2,0,new QTableWidgetItem("Mar"));
    ui->tableWidget->setItem(2,1,new QTableWidgetItem("Mar"));
    ui->tableWidget->setItem(2,2,new QTableWidgetItem("Mar"));

    
    connect(ui->btnMusic, &QPushButton::clicked, this, [=]()
    {
        ui->stackedWidget->setCurrentIndex(0);
    });
    connect(ui->btnVideo, &QPushButton::clicked, this, [=]()
    {
        ui->stackedWidget->setCurrentWidget(ui->video);
    });
    connect(ui->btnOther, &QPushButton::clicked, this, [=]()
    {
        ui->stackedWidget->setCurrentIndex(2);
    });

    //ui->image->setPixmap(QPixmap(":/Image/Luffy.png"));
    QMovie* movie = new QMovie(":/Image/mario.gif");
    ui->image->setMovie(movie);
    movie->start(); // 启动播放
}

Widget::~Widget()
{
    delete ui;
}

 

QLable

#include "mywidget.h"
#include "ui_mywidget.h"
#include <QListWidget>
#include <QListWidgetItem>
#include <QTableWidget>
#include <QTableWidgetItem>
#include <QMovie>


MyWidget::MyWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MyWidget)
{
    ui->setupUi(this);
    ui->listWidget->addItem("hello world");
    QListWidgetItem *item = new QListWidgetItem(QIcon(":/Image/Luffy.png"),"Luffy",ui->listWidget);
    ui->listWidget->addItem(item);

    ui->tableWidget->setRowCount(100);
    ui->tableWidget->setColumnCount(3);
    QStringList h_list;
    h_list << "姓名" << "性别" << "年龄" ;
    ui->tableWidget->setHorizontalHeaderLabels(h_list);

    //QTableWidgetItem *t_item = new QTableWidgetItem(QIcon(":/Image/face.png"),"haha");
    ui->tableWidget->setItem(0,0,new QTableWidgetItem(QIcon(":/Image/face.png"),"haha"));
    ui->tableWidget->setItem(0,1,new QTableWidgetItem(QIcon(":/Image/face.png"),"haha"));
    ui->tableWidget->setItem(0,2,new QTableWidgetItem(QIcon(":/Image/face.png"),"haha"));

    ui->tableWidget->setItem(2,0,new QTableWidgetItem("Mar"));
    ui->tableWidget->setItem(2,1,new QTableWidgetItem("Mar"));
    ui->tableWidget->setItem(2,2,new QTableWidgetItem("Mar"));

    QStringList l_text;
    l_text << "北京" << "上海" << "深圳";
    ui->comboBox->addItems(l_text);

    connect(ui->btmMusic,&QPushButton::clicked,this,[=](){
        ui->stackedWidget->setCurrentIndex(0);
    });

    connect(ui->btnMovie,&QPushButton::clicked,this,[=](){
        ui->stackedWidget->setCurrentIndex(1);
    });

    connect(ui->btnOther,&QPushButton::clicked,this,[=](){
        ui->stackedWidget->setCurrentIndex(2);
    });

    //QLabel *qlb = new QLabel(this);
    ui->Iconlabel->setPixmap(QPixmap(":/Image/butterfly1.png"));

    QMovie *movie = new QMovie(":/Image/mario.gif");
    ui->movie_label->setMovie(movie);
    movie->start(); // 启动播放
}

MyWidget::~MyWidget()
{
    delete ui;
}

 

posted @ 2019-04-22 17:55  狂奔~  阅读(506)  评论(0编辑  收藏  举报