您的位置:首页 > 编程语言 > Qt开发

QT11 How to set image with QLabel in Qt

2016-03-30 01:38 501 查看
1. drag a label widget on the window, remove the string contained:



2. insert two lines into class login constructor function in login.cpp:

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

QPixmap pix("C:/TestQT/QT_SQLite/Tutorial7_How_to_connect_Qt_to_SQLite/Sqlite_DB/icon/panda.png");
ui->label_pic->setPixmap(pix);

mydb = QSqlDatabase::addDatabase("QSQLITE");
mydb.setDatabaseName("C:/work_files/sqlite-tools-win32-x86-3110100/company.db");

if(!mydb.open())
ui->label->setText("Failed to open the database");
else
ui->label->setText("Connected...");
}

3. the running result:



4. the other way to set image with QLabel:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: