Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

PrintPreviewDialog issue on 4K monitor



  • Hello!

    I have added the print preview feature to my program. The problem is, it displays the preview document not well on the screen resolutions above the 1920x1080.

    Example:
    2021-02-14_235401.png

    Code:

    QFont docFont;
    docFont.setPointSize(14);
    QTextDocument *textDoc = new QTextDocument(this);
    textDoc->setDefaultFont(docFont);
    textDoc->setPlainText(getHardwareData());
    

    Is there any hint/font to make it look well on all screens resolutions on Windows? Thank you.



  • During a debugging process I have found the following issues:

    QWindowsMultiFontEngine::loadEngine: CreateFontFromLOGFONT failed for "Courier": error 0x88985002 : Indicates the specified font does not exist.
    QWindowsMultiFontEngine::loadEngine: CreateFontFromLOGFONT failed for "Courier": error 0x88985002 : Indicates the specified font does not exist.
    


  • I have fixed the QWindowsMultiFontEngine::loadEngine: CreateFontFromLOGFONT failed for "Courier" issue. The problem was caused by a Unicode character in Peripheral data. Now, the only thing left is to make it look better on 4K.



  • I have found some hack to get the toolbar actions from a print preview dialog. By adding some additional logic it fixed the issue.

        QList<QToolBar*> toolbarList = printPreviewDlg->findChildren<QToolBar*>();
    
        if (!toolbarList.isEmpty()) {
            if (screenSize.width() > 1920 && screenSize.height() > 1080) {
                toolbarList.first()->actions().at(0)->activate(QAction::Trigger);
            } else {
                toolbarList.first()->actions().at(1)->activate(QAction::Trigger);
            }
        }
    

    To detect the screen size I use the native Win API methods. Now, it automatically triggers the Fit to width toolbar option and sets a better preview on 4K monitor. It works depending on the screen size. The issue is resolved.


Log in to reply