Repository navigation
fix: use DevicePixel for print page rect under Qt6 - #672
Merged
deepin-bot[bot] merged 1 commit intoOct 20, 2026
Merged
deepin-bot[bot] merged 1 commit into
deepin-bot[bot] merged 1 commit into
Conversation
1. Qt6 print engines use the printer's native resolution, not 72 DPI. 2. pageRect(Point) broke unit consistency: margins and fonts are in device pixels, so layout got wrong scale and negative title box. 3. Restore Qt5 pageRect() semantics by using DevicePixel in all 3 print paths (doPrint, doPrintWithLargeDoc, asynPrint). Log: Fixed broken Qt6 print layout: oversized text, wrong page count and missing page numbers. Influence: 1. Open a text file, press Ctrl+P, check 2cm margins and normal font size in print preview. 2. Export to PDF (A4) from the print dialog and verify total page count and bottom-right page numbers. 3. Open a large file (>1MB) to hit the large-doc print path and flip preview pages to check layout stability. fix: 修复Qt6下打印页面矩形单位错误导致的排版异常 1. Qt6 打印引擎使用打印机原生分辨率,不再默认 72 DPI。 2. pageRect(Point) 与边距、字号的设备像素单位不一致,导致缩放 错误且页码框宽度为负。 3. 三处打印路径(doPrint/doPrintWithLargeDoc/asynPrint)恢复 Qt5 pageRect() 的设备像素语义。 Log: 修复 Qt6 下打印及打印预览排版错乱(文字过大、页数异常、 页码缺失)的问题。 Influence: 1. 打开文本文件,Ctrl+P 打印预览,检查 2 厘米页边距与字号是否 正常。 2. 在打印对话框导出 PDF(A4),检查总页数与右下角页码是否 正确。 3. 打开大文件(大于 1MB)走大文档打印路径,翻页预览检查排版 稳定。 PMS: BUG-380145
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates all Qt6 printing paths to obtain page rectangles in device pixels, matching painter coordinates and existing margin, font-size, page-size, and pagination calculations; Qt5 behavior remains unchanged. Sequence diagram for Qt6 device-pixel print layoutsequenceDiagram
participant Window
participant DPrinter
participant QPainter
Window->>DPrinter: pageRect(QPrinter::DevicePixel)
DPrinter-->>Window: pageRect in device pixels
Window->>QPainter: render page using matching coordinates
QPainter-->>Window: print or preview output with consistent layout
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 当前修改已正确,无需额外修复。 // Qt6 下使用 DevicePixel 获取设备像素坐标的页面矩形: #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QRectF pageRect(printer->pageRect());
#else
QRectF pageRect(printer->pageRect(QPrinter::DevicePixel));
#endif本报告由 AI 代码审查工具自动生成 |
lzwind
approved these changes
Oct 20, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Qt6 打印引擎使用打印机原生分辨率(
setResolution()已废弃无效),而pageRect(QPrinter::Point)返回磅(1/72 英寸)单位,与代码中按设备像素计算的页边距、字号、setPageSize不一致,导致打印及打印预览排版错乱:文字过大、每行字符极少、总页数异常、页码框宽度为负不显示。Changes
src/widgets/window.cpp三处打印路径(doPrint/doPrintWithLargeDoc/asynPrint)将pageRect(QPrinter::Point)改为pageRect(QPrinter::DevicePixel),恢复 Qt5 无参pageRect()的设备像素语义,与 painter 坐标系及边距/字号计算单位保持一致。Testing
PMS: BUG-380145
Summary by Sourcery
Bug Fixes: