Properly calculate a lot of things related to these layouts. (#5817)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-04-09 18:09:04 +02:00 committed by GitHub
parent 6661a5d946
commit 80b6d6a31f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 118 additions and 99 deletions

View file

@ -26,14 +26,14 @@ FlowWidget::FlowWidget(QWidget *parent,
{
// Main Widget and Layout
if (_flowDirection == Qt::Horizontal) {
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
this->setMinimumWidth(0);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
setMinimumWidth(0);
} else {
this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
this->setMinimumHeight(0);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
setMinimumHeight(0);
}
mainLayout = new QHBoxLayout(this);
this->setLayout(mainLayout);
setLayout(mainLayout);
if (horizontalPolicy != Qt::ScrollBarAlwaysOff || verticalPolicy != Qt::ScrollBarAlwaysOff) {
// Scroll Area, which should expand as much as possible, since it should be the only direct child widget.

View file

@ -41,9 +41,8 @@ OverlapWidget::OverlapWidget(QWidget *parent,
: QWidget(parent), overlapPercentage(overlapPercentage), maxColumns(maxColumns), maxRows(maxRows),
direction(direction), adjustOnResize(adjustOnResize)
{
this->setMinimumSize(0, 0);
overlapLayout = new OverlapLayout(this, overlapPercentage, maxColumns, maxRows, direction);
this->setLayout(overlapLayout);
overlapLayout = new OverlapLayout(this, overlapPercentage, maxColumns, maxRows, direction, Qt::Horizontal);
setLayout(overlapLayout);
}
/**
@ -57,7 +56,12 @@ OverlapWidget::OverlapWidget(QWidget *parent,
*/
void OverlapWidget::addWidget(QWidget *widgetToAdd) const
{
this->overlapLayout->addWidget(widgetToAdd);
overlapLayout->addWidget(widgetToAdd);
}
void OverlapWidget::removeWidget(QWidget *widgetToRemove) const
{
overlapLayout->removeWidget(widgetToRemove);
}
/**
@ -72,8 +76,8 @@ void OverlapWidget::clearLayout()
if (overlapLayout != nullptr) {
QLayoutItem *item;
while ((item = overlapLayout->takeAt(0)) != nullptr) {
delete item->widget(); // Delete the widget
delete item; // Delete the layout item
item->widget()->deleteLater();
delete item;
}
}

View file

@ -17,6 +17,7 @@ public:
Qt::Orientation direction,
bool adjustOnResize = false);
void addWidget(QWidget *widgetToAdd) const;
void removeWidget(QWidget *widgetToRemove) const;
void clearLayout();
void adjustMaxColumnsAndRows();