PDA

View Full Version : QPageSetupDialog problem



mendynew
15th March 2008, 02:50
I used qt 4.2.2 on windows.


QPrinter printer;
printer.setResolution(QPrinter::HighResolution);
QPageSetupDialog psd(&printer);
if(psd.exec() != QDialog::Accepted)
return;
......

QPageSetupDialog will show native page setup dialog.
I can set margins in this dialog, however, it will not tak any effect.
When reopen the dialog, the margin will be the default values.
I tried to manually to set QPrinter's page rectangle via
printer.printEngine->setProperty(QPrintEngine::PPK_PageRect,...).
But it does not work either.

I don't know there's any way to set the margin in page setup dialog.
Thanks!

mendynew
17th March 2008, 06:01
help me please!

Weilor
17th March 2008, 09:49
You create a new QPrinter object on the stack every time you enter your function. So every change you make will be deleted together with your QPrinter object at the end of your function. Try to create a member variable of QPrinter on the heap. This will allow you to save your changes.

HTH,
Weilor

mendynew
19th March 2008, 01:50
Oh, actually the QPrinter object is a member variable in my code. It seems that you did not have a try. It will remember all the settings except margins. I found the same problem on the demo example of qt.
$(QTDIR)\demos\textedit.
Is this a bug for Qt?

Thanks all the same!

Weilor
19th March 2008, 08:26
Well, in the code you posted here printer is not a member variable, so I thought that there might be the problem.
Anyway, I tested the textedit demo with Qt4.2.2 on windows and I did not run into the problem you mentioned. The QPageSetupDialog remembers all settings, even the margins. If this problem occurs even in the demo you should check your Qt installation or upgrade to a newer version or contact Trolltech.

Greets,
Weilor

mendynew
19th March 2008, 09:07
It is a so strange problem, I tested this on other colleagues' machines and it did appear. My qt's version is commercial 4.2.2. I tried to follow up the source code. QPrinter does not provide any API for setting margins! But I find such API in 4.4 beta1.
Weilor, would you mind sending me the demo textedit's binary?
My mail is mendynew@163.com
Thanks very much!