Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/widgets/dprintpreviewdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion tests/testcases/printpreview/ut_dprintpreviewdialog.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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());
Expand Down
Loading