QDataWidgetMapper 不适用于 QLabels [英] QDataWidgetMapper not working with QLabels

查看:40
本文介绍了QDataWidgetMapper 不适用于 QLabels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QDataWidgetMapper 将数据映射到 QLineEdit,它工作正常.当我使用将数据映射到 QLabel 时,它不会在标签中显示任何数据.我尝试按以下方式进行:

I am using QDataWidgetMapper to map data to a QLineEdit and it works fine. When I use to map data to a QLabel it does not show any data in the label.I am trying to do it in the following way:

QDataWidgetMapper *testMapper=new QDataWidgetMapper();

testMapper->setOrientation(Qt::Vertical);
testMapper->setModel(testModel);


//setting the mapper values to the textboxes ----works fine
testMapper->addMapping(ui->LineEdit1,0);
testMapper->addMapping(ui->LineEdit2,1);

//setting it to qlabels
testMapper->addMapping(ui->label,3);----- does not work
testMapper->toFirst();

我从列表中获取值并将列表附加到 QDataWidgetMapper,从映射器我使用 addMapping 将它附加到文本框.谁能告诉我为什么它不适用于 qLabels.

I am getting the values from the list and attaching the list to the QDataWidgetMapper, from the mapper I am using addMapping to append it to the textboxes. Could anyone let me know why it does not work with qLabels.

推荐答案

默认情况下,每个小部件的 用户属性 用于在模型和小部件之间传输数据.QLabel 没有用户属性.您应该使用额外的 addMapping() 函数来启用命名属性而不是默认用户属性.

By default, each widget's user property is used to transfer data between the model and the widget. QLabel has no user property. You should use an additional addMapping() function enables a named property to be used instead of the default user property.

testMapper->addMapping(ui->label,3,"text");

这篇关于QDataWidgetMapper 不适用于 QLabels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆