Skip to content

Commit

Permalink
fix: optimize property dialog layout stretch handling
Browse files Browse the repository at this point in the history
- Move stretch item management to showEvent
- Remove redundant stretch item before adding new one
- Fix potential memory leak by properly deleting old stretch item

This change ensures proper layout spacing in the property dialog and
prevents multiple stretch items from being added unintentionally.

Log:
  • Loading branch information
Johnson-zs committed Dec 9, 2024
1 parent 2a67c6b commit 2018f19
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <QVBoxLayout>
#include <QFrame>
#include <QScreen>
#include <QTimer>

DWIDGET_USE_NAMESPACE
DFMBASE_USE_NAMESPACE
Expand Down Expand Up @@ -130,7 +131,6 @@ void FilePropertyDialog::createPermissionManagerWidget(const QUrl &url)
QVBoxLayout *vlayout = qobject_cast<QVBoxLayout *>(scrollArea->widget()->layout());
if (vlayout) {
insertExtendedControl(vlayout->count(), permissionManagerWidget);
vlayout->addStretch();
}
}

Expand Down Expand Up @@ -314,6 +314,22 @@ void FilePropertyDialog::resizeEvent(QResizeEvent *event)
void FilePropertyDialog::showEvent(QShowEvent *event)
{
DDialog::showEvent(event);

QVBoxLayout *vlayout = qobject_cast<QVBoxLayout *>(scrollArea->widget()->layout());
if (vlayout) {
if (vlayout->count() > 0) {
QLayoutItem *item = vlayout->itemAt(vlayout->count() - 1);
if (item && item->spacerItem()) {
vlayout->removeItem(item);
delete item;
}
}
vlayout->addStretch();
}

QTimer::singleShot(0, this, [this]() {
processHeight(contentHeight());
});
}

void FilePropertyDialog::closeEvent(QCloseEvent *event)
Expand Down

0 comments on commit 2018f19

Please sign in to comment.