I use QVBoxLayout to arrange the vertical stack of widgets. QVBoxLayout is contained in QScrollArea. I want some of the widgets to be hidden initially and only show when the checkbox is selected. Here is an example of the code I'm using.
MyWidget::MyWidget(QWidget *parent) : QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel *labelLogTypes = new QLabel(tr("Log Types"));
m_checkBoxCsv = new QCheckBox(tr("&Delimited File (CSV)"));
m_labelDelimiter = new QLabel(tr("Delimiter:"));
m_lineEditDelimiter = new QLineEdit(",");
checkBoxCsv_Toggled(m_checkBoxCsv->isChecked());
connect(m_checkBoxCsv, SIGNAL(toggled(bool)), SLOT(checkBoxCsv_Toggled(bool)));
QHBoxLayout *layoutDelimitedChar = new QHBoxLayout();
layoutDelimitedChar->addWidget(m_labelDelimiter);
layoutDelimitedChar->addWidget(m_lineEditDelimiter);
m_checkBoxXml = new QCheckBox(tr("&XML File"));
m_checkBoxText = new QCheckBox(tr("Plain &Text File"));
layout->addWidget(labelLogTypes);
layout->addWidget(m_checkBoxCsv);
layout->addLayout(layoutDelimitedChar);
layout->addWidget(m_checkBoxXml);
layout->addWidget(m_checkBoxText);
layout->addStretch();
}
MyWidget::checkBoxCsv_Toggled(bool checked)
{
m_labelDelimiter->setVisible(checked);
m_lineEditDelimiter->setVisible(checked);
}
I want to m_labelDelimiter, and m_lineEditDelimiterboth were initially invisible, and I want them to be switched to the state of visibility m_checkBoxCsv. When they become visible, I would like the layout to expand vertically to fit them.
This code achieves the desired functionality, but does not seem to leave room for the two initially hidden widgets. When I check the box, they become visible, but they all look smoothed to fit them.
, , . QVBoxLayout , ?
QScrollArea, , . QScrollArea?