@mchinand , this might look a bit over the top, I have a class clsQtLayout which is derived from QWidget, the reason for this is because the class supports layouts with a scrollable area which can only be accommodated by using a widget to contain everything.
After much work the QVBoxLayout works great, I have a form layout inside that can have a fixed height and in my example contains radio buttons, it can be scrollable within the vertical layout.
I have tried the same techniques for the QHBoxLayout and this is where I'm having problems, for some reason which I'm not seeing it just doesn't work. Going back to my XML:
<layout type="form" height="72" hspacing="0">
<buttongroup id="enSEX" dbfield="vcSex"/>
<radiobutton id="rdoM" group="enSEX" text="Male" default="true" position="0,0"/>
<radiobutton id="rdoF" group="enSEX" text="Female" position="1,0"/>
</layout>
This XML behind the scenes creates a QVBoxLayout because the height of the required QFormLayout has a fixed height. A QWidget is created which the QScrollArea connected to. The QScrollArea is then connected to the QVBoxLayout.
if ( intFixedHeight > 0 ) {
//Create a vertical layout as the container for this layout
pobjVBox = new QVBoxLayout;
//Create and set-up scroll area
mpobjScroller = new QScrollArea;
mpobjScroller->setWidget(pobjContainer);
mpobjScroller->setFixedHeight(intFixedHeight);
pobjVBox->addWidget(mpobjScroller);
}
pobjLayout = new QFormLayout;
//Set-up form
pobjLayout->setContentsMargins(0,0,0,0);
pobjLayout->setSpacing(0);
QString strHorzSpacing(mpobjNode->strGetAttribute(
clsXMLnode::mscszAttrSpacingH));
if ( strHorzSpacing.isEmpty() != true ) {
((QFormLayout*)pobjLayout)->setHorizontalSpacing(strHorzSpacing.toInt());
}
if ( pobjContainer != nullptr ) {
pobjContainer->setLayout(pobjLayout);
}
This all works fine, the following XML is for the horizontal layout:
<layout id="btnbarLO" type="horizontal" width="128">
<groupbox id="btnbar" layout="btnbarLO" properties="background-color:#ff0000;"/>
<button id="btnApply" group="btnbar" api="applyChanges">
<subscriber signal="clicked" target="simon2.js@applyButton"/>
</button>
<button id="btnUndo" group="btnbar" api="undoChanges"/>
<button id="btnOK" group="btnbar" api="submitAndClose"/>
</layout>
And the code in the layout class for this, which should be very similar to the vertical layout:
if ( intFixedWidth > 0 ) {
//Create a vertical layout as the container for this layout
pobjHBox = new QHBoxLayout;
//Create and set-up scroll area
mpobjScroller = new QScrollArea;
mpobjScroller->setWidget(pobjContainer);
mpobjScroller->setFixedWidth(intFixedWidth);
pobjHBox->addWidget(mpobjScroller);
}
pobjLayout = new QHBoxLayout;
//Set-up form
pobjLayout->setContentsMargins(0,0,0,0);
pobjLayout->setSpacing(0);
QString strHorzSpacing(mpobjNode->strGetAttribute(
clsXMLnode::mscszAttrSpacingH));
if ( strHorzSpacing.isEmpty() != true ) {
((QHBoxLayout*)pobjLayout)->addSpacing(strHorzSpacing.toInt());
}
if ( pobjContainer != nullptr ) {
pobjContainer->setLayout(pobjLayout);
}
However this isn't working and the results are as shown in the original screenshot:
[image: 90103c88-c687-4459-883b-84d414bc1e2e.png]
I've set the background colour of the QGroupBox to red to clarify where it is.
[edit] I can see it isn't clear, so elsewhere in my node handling code there is this logic where nodes are appended to parent nodes:
QWidget* pobjWChild(pobjChild->pobjGetWidget());
if ( pobjWChild != nullptr && mstrName.compare(clsXMLnode::mscszNodeLayout) == 0 ) {
//Yes, does the parent have a layout?
QLayout* pobjLayout(pobjGetLayout());
if ( pobjLayout != nullptr ) {
QString strType(strGetAttribute(clsXMLnode::mscszAttrType));
QFormLayout* pobjForm(qobject_cast<QFormLayout*>(pobjLayout));
//Add the widget for the layout
if ( pobjForm != nullptr
&& strType.compare(clsXMLnode::mscszLayoutVertical) == 0 ) {
pobjForm->addRow(pobjWChild);
} else {
pobjLayout->addWidget(pobjWChild);
}
}
}