Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved PrintPreviewDialog issue on 4K monitor

    General and Desktop
    1
    4
    108
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Cobra91151
      Cobra91151 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • Cobra91151
        Cobra91151 last edited by

        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.
        
        1 Reply Last reply Reply Quote 0
        • Cobra91151
          Cobra91151 last edited by Cobra91151

          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.

          1 Reply Last reply Reply Quote 0
          • Cobra91151
            Cobra91151 last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post