Print html page margin problem (QTextDocument, QPrintPreviewDialog)



  • I tried following code snippets:

    QPrintPreviewDialog *dialog = new QPrintPreviewDialog(&printer);
    dialog->setWindowTitle("Druckansicht");
    
    dialog->setGeometry(20,30,1280,900);
    
    connect(dialog,SIGNAL(paintRequested(QPrinter*)),this,SLOT(print(QPrinter*)));
    dialog->exec();
    

    void MainWindow::print(QPrinter *printer)
    {
    QFile file(_htmlFilePath);

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        qWarning("fehler datei nicht gefunden: ");
        qWarning(_htmlFilePath.toStdString().c_str());
        std::cout << file.isOpen() << file.fileName().toStdString().c_str() << std::endl;
        exit(EXIT_FAILURE);
    }
    
    QString htmlContent;
    QTextStream in(&file);
    in.setCodec("UTF-8");
    htmlContent = in.readAll();
    
    QTextDocument *doc = new QTextDocument();
    doc->setHtml(htmlContent);
    doc->print(printer);
    

    }

    The printpreview is shown. It is possible to change the page paper size and the oriantation of the page
    When i try to change the page margins in the page setup nothing happens.
    Is that a bug or do i something wrong?


  • Moderators

    @mschmit

    What OS are you using?

    My guess is that you are using the native dialog for your preview. Therefore, I personally doubt that this is influenced by Qt. Such things are most of the time dependent on the actual driver used.



  • we use windows in my case windows 7 x64.

    the print preview is the QPrintPreviewDialog and not the OS specific dialog. Or do you mean the page setup dialog?

    How can i fix or solve this problem?


  • Moderators

    @mschmit

    AFAIK general dialogs as file dialog, printer dialog, preview and so on are the native dialogs of the OS in your case windows. Qt is providing only an identical interface for use on different platforms (OS). The options of your dialog will change sometimes with the actual printer driver, since not every printer has the same options.
    Based on my experience changing page size and orientation is typically the easy stuff and not of a major problem. With margins it is typically more complicated. Also WinWord for instance cannot always handle that stuff accurately. For one printer you set every thing up, but when changing the printer everything is messed up and you might even find a solution.

    You can check the actual values of pageLayout set for the current printer. You can also ensure in QTextDocument that there are no different margins or other layout setups.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.