我有以下简单代码:
UeDisplaySettingsWidget::UeDisplaySettingsWidget(QWidget *parent)
: QWidget(parent)
{
this->setLayout(new QFormLayout());
this->ueSetDisplayDimmerSelectorLayout(new QHBoxLayout());
this->ueSetDisplayDimmerSelectorLabel(new QLabel(tr("Display fade level:"),
this));
this->ueInitDisplayDimmerLevelSelector();
this->ueInitDisplayDimmerTimeoutSelector();
connect(this->ueDisplayDimmerSelector(),
&QSlider::valueChanged,
this,
&UeDisplaySettingsWidget::ueSlotDisplayDimerSelectorValueChanged);
this->ueDisplayDimmerSelectorLayout()->addWidget(this->ueDisplayDimmerSelectorLabel());
this->ueDisplayDimmerSelectorLayout()->addWidget(this->ueDisplayDimmerSelector());
this->ueDisplayDimmerSelectorLayout()->addWidget(this->ueDisplayDimmerCurrentLevelIndicator());
dynamic_cast<QFormLayout*>(this->layout())->addItem(this->ueDisplayDimmerSelectorLayout());
dynamic_cast<QFormLayout*>(this->layout())->addRow(tr("Display fade timeout:"),
this->ueDisplayDimmerTimeoutSelector());
} // constructor
现在,为什么this->ueDisplayDimmerSelectorLayout()
由[{1}}返回并包含QHBoxLayout文字显示淡入淡出级别:,QLabel和QSlider未与QLCDNumber的下一行对齐?
答案 0 :(得分:1)
QFormLayout基本上是一个网格布局,有两列,左栏中有标签,右边有标签。
由于某种原因,你可以在水平布局中淡出标签this-&gt; ueDisplayDimmerSelectorLabel()并为你的第一行和QFormLayout :: addRow使用QFormLayout :: addItem(QLayoutItem *)(const QString&amp;,QWidget * ))第二行。这就是为什么你的DisplayDimmerSlectorLabel与第二列中的小部件一起。没有测试它应该看起来像这样:
connect(this->ueDisplayDimmerSelector(),
&QSlider::valueChanged,
this,
&UeDisplaySettingsWidget::ueSlotDisplayDimerSelectorValueChanged);
this->ueDisplayDimmerSelectorLayout()->addWidget(this->ueDisplayDimmerSelector());
this->ueDisplayDimmerSelectorLayout()->addWidget(this->ueDisplayDimmerCurrentLevelIndicator());
dynamic_cast<QFormLayout*>(this->layout())->addRow(tr("Display fade level:"), this->ueDisplayDimmerSelectorLayout());
dynamic_cast<QFormLayout*>(this->layout())->addRow(tr("Display fade timeout:"),
this->ueDisplayDimmerTimeoutSelector());