我想从 .ini 文件为我的 hello-world QT + C++ 程序动态创建接口(interface)。
1 步骤我使用 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);
}
一切看起来都很棒——QLabel 包含图像的文件路径,TAB 的 header 包含来自 iniFile 的正确名称。但!我想将 setPixmap() 设置为 QLabel,这是问题所在。 new QLabel()
查询没有任何可用于设置任何选项的名称。请帮我解决这个问题 for(){}
最佳答案
你可以这样转换:
QPixmap pix(Imgpath);
tab.addTab(new QLabel(Imgpath, &tab), tName);
到:
QLabel* label = new QLabel(Imgpath, &tab);
label->setPixmap(QPixmap(Imgpath));
tab.addTab(label, tName);
关于c++ - QTabWidget 中的 Qt4 QLabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21080464/