QPrintPreviewDialog 不正确的预览 [英] QPrintPreviewDialog incorrect preview

查看:84
本文介绍了QPrintPreviewDialog 不正确的预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用QPrintPreviewDialog预览打印,我使用如下代码

Using QPrintPreviewDialog to preview the print, I use the following code

    QPrinter printer;
    printer.setResolution(QPrinter::HighResolution);
    printer.setPaperSize(QPrinter::A4);
    printer.setOrientation(QPrinter::Portrait);
    QPrintPreviewDialog *pd = new QPrintPreviewDialog(&printer);
    connect(pd,SIGNAL(paintRequested(QPrinter*)),this,SLOT(print(QPrinter*)));
    pd->exec();


void Class::print(QPrinter *p)
{
    QTextEdit *ted = new QTextEdit;
    ted->insertHtml("<center><img src='"+QString(":/img/logo.png")+"' width='90' height='72'/><b><font size='9'>Logo Text</font></b></center>");
    ted->document()->print(p);
}

按下打印按钮时,会出现此对话框:

On pushing the print button, this dialog appears:

如您所见,内容遍布整个页面.然后我点击预览对话框上的页面设置按钮,出现:

As you can see the content is spread all over the page. Then I click the page setup button on the preview dialog and this appears:

没有改变任何东西,我点击确定,然后预览变得正确:

without changing anything, I click OK and then the preview becomes correct:

问题是如何通过代码修正预览?

推荐答案

添加一个 QPageSetupDialog 在预览前显示.

Add a QPageSetupDialog to show before preview.

这篇关于QPrintPreviewDialog 不正确的预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆