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 a19813a
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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 +313,18 @@ 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();
}
}

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

0 comments on commit a19813a

Please sign in to comment.