Skip to content

Commit

Permalink
[AttributeForm] respect size policy of embedded widgets (#45990)
Browse files Browse the repository at this point in the history
* [AttributeForm] respect size policy of embedded widgets

This let widgets wich can make use of more vertical space grow
togheter with the form dialog

* Check for more not expanding policies
  • Loading branch information
domi4484 committed Nov 11, 2021
1 parent a2de61c commit 1e8f64d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/gui/qgsattributeform.cpp
Expand Up @@ -1561,6 +1561,7 @@ void QgsAttributeForm::init()
int column = 0;
int columnCount = 1;
bool hasRootFields = false;
bool addSpacer = true;

const QList<QgsAttributeEditorElement *> tabs = mLayer->editFormConfig().tabs();

Expand Down Expand Up @@ -1640,6 +1641,12 @@ void QgsAttributeForm::init()

label->setBuddy( widgetInfo.widget );

// If at least one expanding widget is present do not add a spacer
if ( widgetInfo.widget->sizePolicy().verticalPolicy() != QSizePolicy::Fixed
&& widgetInfo.widget->sizePolicy().verticalPolicy() != QSizePolicy::Maximum
&& widgetInfo.widget->sizePolicy().verticalPolicy() != QSizePolicy::Preferred )
addSpacer = false;

if ( !widgetInfo.showLabel )
{
QVBoxLayout *c = new QVBoxLayout();
Expand Down Expand Up @@ -1690,7 +1697,7 @@ void QgsAttributeForm::init()
}
}

if ( hasRootFields )
if ( hasRootFields && addSpacer )
{
QSpacerItem *spacerItem = new QSpacerItem( 20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding );
layout->addItem( spacerItem, row, 0 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsattributeformeditorwidget.cpp
Expand Up @@ -46,7 +46,7 @@ QgsAttributeFormEditorWidget::QgsAttributeFormEditorWidget( QgsEditorWidgetWrapp

mMultiEditButton->setField( mEditorWidget->field() );
mAggregateButton = new QgsAggregateToolButton();
mAggregateButton->setType( editorWidget->field().type() );
mAggregateButton->setType( mEditorWidget->field().type() );
connect( mAggregateButton, &QgsAggregateToolButton::aggregateChanged, this, &QgsAttributeFormEditorWidget::onAggregateChanged );

if ( mEditorWidget->widget() )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsattributeformwidget.cpp
Expand Up @@ -60,6 +60,9 @@ QgsAttributeFormWidget::QgsAttributeFormWidget( QgsWidgetWrapper *widget, QgsAtt

mEditPage->layout()->addWidget( mWidget->widget() );

// Respect size policy of embedded widget
setSizePolicy( mWidget->widget()->sizePolicy() );

updateWidgets();
}

Expand Down

0 comments on commit 1e8f64d

Please sign in to comment.