Skip to content

Commit

Permalink
BUG: Fix ctkFlowLayout regression related to minimum size computation
Browse files Browse the repository at this point in the history
This commit fixes a regression introduced in e663242 (COMP: Fix deprecated
warning related to QWidget::getContentsMargins()).

Since functions QWidget::contentsRect() and QWidget::contentsMargins() are
not equivalent, the logic associated with ctkFlowLayout::minimumSize()
and ctkFlowLayout::sizeHint() was incorrect.

Fixes Slicer/Slicer#7108

Reported-by: Csaba Pinter <[email protected]>
Co-authored-by: Andras Lasso <[email protected]>
  • Loading branch information
jcfr and lassoan committed Jul 20, 2023
1 parent 9856b3f commit 1feb498
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Libs/Widgets/ctkFlowLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,12 @@ QSize ctkFlowLayout::minimumSize() const
}
size = size.expandedTo(item->minimumSize());
}
size += this->contentsRect().size();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
size = size.grownBy(this->contentsMargins());
#else
QMargins margins = this->contentsMargins();
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
#endif
return size;
}

Expand Down Expand Up @@ -475,7 +480,12 @@ QSize ctkFlowLayout::sizeHint() const
size += QSize((countX-1) * this->horizontalSpacing(),
(countY-1) * this->verticalSpacing());
// Add margins
size += this->contentsRect().size();
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
size = size.grownBy(this->contentsMargins());
#else
QMargins margins = this->contentsMargins();
size += QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
#endif
return size;
}

Expand Down

0 comments on commit 1feb498

Please sign in to comment.