QTabWidget中的Qt4 QLabel 我想动态创建从H.ini文件中的Hello World Qt+C++程序的接口。p>

QTabWidget中的Qt4 QLabel 我想动态创建从H.ini文件中的Hello World Qt+C++程序的接口。p>,c++,qt,qtgui,qlabel,qtabwidget,C++,Qt,Qtgui,Qlabel,Qtabwidget,第一步我用QSettings读取设置文件-很简单 第2步我尝试绘制界面: //i == 5; for(int temp=1;temp <= i;temp++){ QString tName = settings.value("/Level" + QString::number(temp) + "/Name", "").toString(); QString tImage = settings.value("/Level" + QString::number(temp) +

第一步我用QSettings读取设置文件-很简单

第2步我尝试绘制界面:

//i == 5;
for(int temp=1;temp <= i;temp++){
    QString tName = settings.value("/Level" + QString::number(temp) + "/Name", "").toString();
    QString tImage = settings.value("/Level" + QString::number(temp) + "/Image", "").toString();
    QString Imgpath = QApplication::applicationDirPath() + "/images/" + tImage;
    QPixmap pix(Imgpath);
    tab.addTab(new QLabel(Imgpath, &tab), tName);
}
//i==5;
对于(int temp=1;temp,您可以将其转换为:

QPixmap pix(Imgpath);
tab.addTab(new QLabel(Imgpath, &tab), tName);
致:


您可以使用Pixmap属性:

此属性保存标签的pixmap

如果未设置pixmap,则返回0

设置pixmap将清除以前的任何内容。好友快捷方式(如果有)将被禁用

因此,您可以在标签上设置pixmap,如下所示:

//i == 5;
for (int temp = 1; temp <= i; ++temp) {
    QString tName = settings.value("/Level" + QString::number(temp) + "/Name", "").toString();
    QString tImage = settings.value("/Level" + QString::number(temp) + "/Image", "").toString();
    QString Imgpath = QApplication::applicationDirPath() + "/images/" + tImage;
    QPixmap pix(Imgpath);
    QLabel *myLabel = new QLabel(Imgpath, &tab);
    myLabel->setPixmap(pix);
    tab.addTab(myLabel, tName);
}
//i==5;
对于(int temp=1;temp setPixmap(pix);
tab.addTab(myLabel,tName);
}

“新的QLabel()查询没有任何可用于设置任何选项的名称”--这意味着什么?您是否试图在选项卡名称旁边绘制一个图标,或制作一个在选项卡中显示图像的选项卡小部件?“这意味着什么?”-我的意思是这里没有
QLabel lbl();
在这段代码中,我不知道在哪里可以添加这段代码,然后使用
lbl.setPixmap(LinkToPix);
//i == 5;
for (int temp = 1; temp <= i; ++temp) {
    QString tName = settings.value("/Level" + QString::number(temp) + "/Name", "").toString();
    QString tImage = settings.value("/Level" + QString::number(temp) + "/Image", "").toString();
    QString Imgpath = QApplication::applicationDirPath() + "/images/" + tImage;
    QPixmap pix(Imgpath);
    QLabel *myLabel = new QLabel(Imgpath, &tab);
    myLabel->setPixmap(pix);
    tab.addTab(myLabel, tName);
}