[英]List of spinboxes, displaying only values changed
So, I have an extensive list of spinboxes (30) in one tab and a confirmation page on another tab. 因此,我在一个选项卡中有一个广泛的旋转框列表(30),在另一个选项卡中有一个确认页面。 How can I can display only the names and values of those above 0 in the confirmation page? 如何在确认页面中仅显示大于0的名称和值?
Not sure if it matters, I'm doing this in Qt. 不确定是否重要,我正在Qt中进行此操作。
If I were you, I would be writing something like this: 如果我是你,我会写这样的东西:
#include <QString>
#include <QSpinBox>
#include <QList>
#include <QLabel>
...
void ConfirmationPage::displaySpinBoxNameValues()
{
QString myText;
// Get the spinboxes from your tab.
// Use pointer anywhere here if you use that
foreach (SpinBox spinbBox, SpinBoxList) {
if (spinBox.value() > 0) {
myText.append(QString("Name: ") + spinBox.text());
myText.append(QString("\tValue: ") + spinBox.value());
myText.append('\n');
}
}
if (myText.isEmpty())
myText.append("No QSpinBox has value greater than zero!\n");
// Could be a QLabel, etc.
myDisplayWidget.setText(myText);
}
...
You would need the following method documentations to understand the methods used for this: 您需要以下方法文档来了解用于此目的的方法:
You can obtain the list of spinboxes and iterate over them like: 您可以获取旋转框列表并对其进行迭代,如下所示:
QList<QSpinBox *> list = this->findChildren<QSpinBox *>();
foreach(QSpinBox *spin, list)
{
if(spin->value()>0)
{
QDebug()<< spin->objectName();
}
}
You can get the name of the object by objectName()
if you have previously assigned names to your spinboxes by setObjectName(const QString &name)
. 如果之前已通过setObjectName(const QString &name)
为旋转框分配名称,则可以通过objectName objectName()
获得对象的setObjectName(const QString &name)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.