c++ - QTabWidget 中的 Qt4 QLabel

标签 c++ qt qtgui qlabel qtabwidget

我想从 .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/

相关文章:

c++ - MPI 代码在超过 2 个节点/进程的最终确定时挂起

c++ - SDL 2 通过 SpriteManager 在屏幕上显示图像,获取指针中断

c++ - 仅打印 QPlainTextEdit 文档纯文本

c++ - 在类方法之间传递 QImage 对象

python - pyqtgraph:在 GLSurfacePlotItem 对象上设置 smooth=False 时出现问题

c++ - 在QT中,如何在收到子部件产生的信号后从父部件中删除子部件?

c++ - C++ 的 Qt webkit 教程

c++ - QWT 安装错误

c++ - 添加图标时QMenu项目文本消失

c++ - 函数返回看似随机的数字,而不是返回变量的值