php打印预览功能,Qt打印预览功能实现疑问:(QPrintPreviewDialog)

Qt打印预览功能实现疑问:(QPrintPreviewDialog)

Qt打印预览功能实现疑问:(QPrintPreviewDialog)

由于需要用到打印预览的功能,于是,Qt Assistant查阅打印预览对话框的使用方法,同时,Qt Demo中查阅相关例子,写出下列程序,但是,程序结果并不能将所创建的QTextEdit内容映入到QPrintPreviewDialog的内容中。即假如我在QTextEdit对象中加入了字符“ABC”,但在QPrintPreviewDialog中还是显示为空。

该如何解决这个问题呢?

已定义了一个类

classsingleText: public QTextEdit

{

Q_OBJECT

public:

singleText(parent * p);

filePrintPreview();

...

};

下面是打印预览功能的实现:

//打印预览

voidsingleText::filePrintPreview()

{

QPrinter printer(QPrinter::HighResolution);

QPrintPreviewDialog preview(&printer, this);

preview.showNormal ();

preview.setWindowTitle(fileName + tr("文件打印预览"));

connect(&preview, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));

preview.exec();

return;

}

带着为什么不能将内容显示进入QPrintPreviewDialog中,将逐个语句再理解一次,另外,还有一点不明白的是,在这个函数中,是什么时候将QTextEdit的内容放入到QPrintPreviewDialog中的呢?

在QPrintPreviewDialog中调入的参数有何用?是为了将这个内容导入?但是它不是一个新建的对象吗?

于是:查阅资料:尝试理解,手工翻译了一下大概意思(本人英语烂烂的,如有出入,希望能校正)。

The QPrinter class is a paint device that paints on aprinter.

QPrinter可以画在“绘图”设备上。可以绘制几何图形。

This device represents a series of pages of printedoutput, and is used in almost exactly the same way as other paint devices suchas QWidget and QPixmap.A set of additional functions are provided to manage device-specific features,such as orientation and resolution, and to step through the pagesin a document as it is generated.

这个设备代表了一系列的输出设备页面,并且它还跟其它的绘图设备 QWidget 和 QPixmap这些具有相同的使用方式。它的特殊的管理方式提供一组增加的功能,如,并且通过文档的页面逐渐产生情况和解决方法。

When printing directly to a printer on Windows or Mac OSX, QPrinter uses the built-in printer drivers. On X11, QPrinter uses the Common Unix PrintingSystem (CUPS) or the standard Unix lpr utilityto send PostScript or PDF output to the printer. As analternative, the printProgram() function can be used to specifythe command or utility to use instead of the system default.

当这个直接绘制一个printer在windows或者苹果系统上,QPrinter使用built-in printer 设备。在X11上,QPrinter使用普通的单元绘制系统或者标准的实用单元发送附言或者pdf输出到printer(这个printer应该是指对象吧)上。由于有可选性,这个printProgram()功能可以被普通的或者实用地去使用,代替了系统默认。

Note that setting parameterslike paper size and resolution on an invalid printer is undefined. You can use QPrinter::isValid() to verify this beforechanging any parameters.

注意设置参数(像纸张大小和解决方法)在一个不定义的无效的printer上。在改变其它参数前你可以使用QPrinter::isVaild()去查证这一点。(简单地说就是用isVaild()可以检验函数的有效性。)

其中在使用中的语句有下面:

QPrinter::HighResolution

On Windows, setsthe printer resolution to that defined for the printer in use. For PostScriptprinting, sets the resolution of the PostScript driver to 1200 dpi.

Note:Whenrendering text on a QPrinter device, it is important to realize that thesize of text, when specified in points, is independent of the resolutionspecified for the device itself. Therefore, it may be useful to specify thefont size in pixels when combining text with graphics to ensure that theirrelative sizes are what you expect.

注意:当在QPrinter设备中实施文本,非常重要去知道text的大小,当它在points,当它指定points,独立的解决方法在自身设备中有指定。否则,当与文本合并图像,它将指定字体大小去确定跟它们有关系的你所采用的大小。

看完这些后,QPrinter的作用自己大概理解成是一种可以定义图像,文本之类的属性的类,并且还支持一些特殊的输出功能。只是。。。当初想要解决的疑问还是没有解决,这个时候有指定将QTextEdit中的内容添加进去么,

QPrinter printer(QPrinter::HighResolution);只是为了定义预览的格式质量吧?

然后,带着为什么这个不能正常在QPrinterPreviewDialog中显示的问题,继续查QPrinterPreviewDialog的相关介绍。。。

Detailed Description

The QPrintPreviewDialog class provides a dialog forpreviewing and configuring page layouts for printer output.

Using QPrintPreviewDialog in your existing application isstraightforward:Createthe QPrintPreviewDialog.

You can construct a QPrintPreviewDialogwith an existing QPrinter object, or you can haveQPrintPreviewDialog create one for you, which will be the system defaultprinter.Connectthe paintRequested() signal to a slot.

When the dialog needs to generate a setof preview pages, the paintRequested() signal will be emitted. Youcan use the exact same code for the actual printing as for having the previewgenerated, including calling QPrinter::newPage() to start a new page in thepreview. Connect a slot to thepaintRequested() signal, where you draw ontothe QPrinter object that is passed into theslot.Call exec().

Call QPrintPreviewDialog::exec() to show thepreview dialog.

In Symbian, there is no support for printing. Hence, thisdialog should not be used in Symbian.

一些相关的函数:

QPrintPreviewDialog( QPrinter * printer, QWidget * parent = 0, Qt::WindowFlags flags = 0 );

QPrintPreviewDialog( QWidget * parent = 0, Qt::WindowFlags flags = 0 );

~QPrintPreviewDialog();

void    open ( QObject * receiver, const char *member );

QPrinter* printer ();

构造函数的声明

QPrintPreviewDialog::QPrintPreviewDialog ( QPrinter * printer, QWidget * parent =0, Qt::WindowFlags flags =0 )

[size=font-size:10.5pt,10.5pt]Constructs a QPrintPreviewDialog based on printer and with parent as the parent widget. The widget flags flags are passed on to the QWidget constructor.

看完了这些,还是没有解决疑问,这几段内容,大概讲了怎么去构造使用这个QPrinterPreviewDialog,不过还是不知道如何将原来的设置值放入到这个dialog中。。。

另外,现在在写的函数还有三个功能没有实现,还有两个功能也是同样的问题,QPrinter的打印功能,还有QPageSetupDialog这功能,不过可能这些都是相通的问题,所以在这里想先请教大家如何去解决这些问题呢?

或者说,

QPageSetupDialog与QTextEdit的数据参数相连接口在哪里呢?

QPrinterPreviewDialog与QTextEdit的数据参数接口在哪里呢?

QPrinter与QTextEdit的数据参数的接口又是在哪里呢?

本人菜鸟,初学Qt,也查阅过不少资料,问题实在靠自己的力量解决,所以在这里带着疑问请教大家,望能解决问题~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值