diff --git a/src/widgets/dprintpreviewdialog.cpp b/src/widgets/dprintpreviewdialog.cpp index 840bc60c4..5da830a36 100644 --- a/src/widgets/dprintpreviewdialog.cpp +++ b/src/widgets/dprintpreviewdialog.cpp @@ -1802,6 +1802,9 @@ void DPrintPreviewDialogPrivate::_q_printerChanged(int index) } } + // The current index may not change when the paper list is rebuilt, so the + // combo-box signal is not guaranteed to apply the selected page size. + matchFitablePageSize(); marginsUpdate(true); paperSizeCombo->blockSignals(false); if (isInited) diff --git a/tests/testcases/printpreview/ut_dprintpreviewdialog.cpp b/tests/testcases/printpreview/ut_dprintpreviewdialog.cpp index 8f1d7e067..c571880b7 100644 --- a/tests/testcases/printpreview/ut_dprintpreviewdialog.cpp +++ b/tests/testcases/printpreview/ut_dprintpreviewdialog.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2021 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later @@ -338,6 +338,21 @@ TEST_F(ut_DPrintPreviewDialog, testPrintDeviceCombo) ASSERT_STREQ(test_dialog_d->pageRangeCombo->currentText().toLocal8Bit(), "All"); } +TEST_F(ut_DPrintPreviewDialog, testPaperSizeAppliedAfterPrinterChanged) +{ + test_dialog_d->paperSizeCombo->setCurrentText("8K"); + ASSERT_EQ(test_dialog_d->printer->pageSize(), QPrinter::Custom); + + // Rebuild the paper-size list while preserving the selected custom size. + // This path blocks the combo-box signal, so the page size must be applied + // explicitly after the selection is restored. + test_dialog_d->printer->setPageSize(QPageSize::A4); + test_dialog_d->_q_printerChanged(test_dialog_d->printDeviceCombo->currentIndex()); + + ASSERT_STREQ(test_dialog_d->paperSizeCombo->currentText().toLocal8Bit(), "8K"); + ASSERT_EQ(test_dialog_d->printer->pageSize(), QPrinter::Custom); +} + TEST_F(ut_DPrintPreviewDialog, testCancelBtn) { ASSERT_TRUE(test_dialog_d->cancelBtn->isEnabled());