Skip to content

Commit 67dc851

Browse files
18202781743deepin-bot[bot]
authored andcommitted
fix: improve dialog sizing and remove unused event filter
1. Enhanced dialog width calculation to respect maximum width constraint 2. Added dynamic height calculation based on layout's total height for the given width 3. Removed unused event filter for title and message labels that handled font changes 4. The event filter was unnecessary as Qt's layout system already handles text wrapping properly Influence: 1. Test dialog resizing with various content lengths 2. Verify dialog respects maximum width settings 3. Check that text wrapping works correctly in title and message labels 4. Test dialog appearance with different font sizes 5. Ensure dialog maintains minimum size requirements fix: 改进对话框尺寸计算并移除未使用的事件过滤器 1. 增强对话框宽度计算以遵循最大宽度约束 2. 添加基于布局总高度的动态高度计算 3. 移除用于标题和消息标签字体变化的未使用事件过滤器 4. 该事件过滤器不再必要,因为Qt的布局系统已能正确处理文本换行 Influence: 1. 测试不同内容长度时的对话框调整大小 2. 验证对话框遵循最大宽度设置 3. 检查标题和消息标签中的文本换行是否正确工作 4. 测试不同字体大小下的对话框外观 5. 确保对话框保持最小尺寸要求 PMS: BUG-331061
1 parent 04913bf commit 67dc851

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

src/widgets/ddialog.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ void DDialogPrivate::updateSize()
218218
if (!q->testAttribute(Qt::WA_Resized)) {
219219
QSize size = q->sizeHint();
220220

221-
size.setWidth(qMax(size.width(), DIALOG::DEFAULT_WIDTH));
221+
size.setWidth(qMin(q->maximumWidth(), qMax(size.width(), DIALOG::DEFAULT_WIDTH)));
222+
if (auto layout = q->layout()) {
223+
size.setHeight(layout->totalHeightForWidth(size.width()));
224+
}
222225
size.setHeight(qMax(size.height(), DIALOG::DEFAULT_HEIGHT));
223226

224227
q->resize(size);
@@ -1191,22 +1194,6 @@ void DDialog::keyPressEvent(QKeyEvent *event)
11911194

11921195
bool DDialog::eventFilter(QObject *watched, QEvent *event)
11931196
{
1194-
Q_D(DDialog);
1195-
1196-
if (watched == d->messageLabel || watched == d->titleLabel) {
1197-
if (event->type() == QEvent::FontChange) {
1198-
QLabel *label = qobject_cast<QLabel *>(watched);
1199-
1200-
if (label && !label->text().isEmpty() && label->wordWrap()) {
1201-
QSize sz = style()->itemTextRect(label->fontMetrics(), label->rect(), Qt::TextWordWrap, false, label->text()).size();
1202-
1203-
label->setMinimumHeight(qMax(sz.height(), label->sizeHint().height()));
1204-
}
1205-
}
1206-
1207-
return false;
1208-
}
1209-
12101197
return DAbstractDialog::eventFilter(watched, event);
12111198
}
12121199

0 commit comments

Comments
 (0)