PrintPreviewDialog issue on 4K monitor

0

I have added a print preview feature to my program. The problem is, it does not display the preview document well on screen resolutions above 1920 x 1080.

Example:

preview

Code:

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

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.

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

Edited: 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.

c++
windows
qt
asked on Stack Overflow Feb 17, 2021 by Hunter91151 • edited Feb 19, 2021 by Hunter91151

1 Answer

0

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.

answered on Stack Overflow Feb 28, 2021 by Hunter91151

User contributions licensed under CC BY-SA 3.0