PDA

View Full Version : Qt3 to Qt4 printer setup confusion



impeteperry
4th May 2006, 13:41
In QT3 the code
QPrinter myprinter; // = new QPrinter();
myprinter.setPageSize( QPrinter::Letter );
myprinter.setOrientation( QPrinter::Portrait );
myprinter.setColorMode( QPrinter::Color );
myprinter.setFullPage ( true );
ret = myprinter.setup();
if( ret == true )
{
QPainter p( &myprinter );gave the user of a program the oppurtunity to change the default perameters for a print out. Qt4 says to use "QPrintDialog printDialog" for this.
The "Detailed Description" for this function says
Typically, QPrintDialog objects are constructed with a QPrinter object, and executed using the exec() function.

QPrintDialog printDialog(printer, parent);
if (printDialog.exec() == QDialog::Accepted) {
// print ...
}

I am a bit of a newbie in deciphering Qt4's style of documentation and with no print examples that I can find I need help.

Thanks

jacek
4th May 2006, 14:33
QPrintDialog printDialog(printer, parent);
if (printDialog.exec() == QDialog::Accepted) {
// print ...
}
It's a Qt4 equivalent of:
ret = myprinter.setup();
if( ret == true )
{
// print ...
}
The "print ..." part didn't change much in Qt4, i.e. it's something like this:
QPainter p;
p.begin( &myprinter );
p.setPen( ... );
p.drawLine( 10, 10, 100, 100 );
...
p.end();

impeteperry
4th May 2006, 21:40
Thanks, actually I am able to print ok in Qt4, but what I wanted is to display a window similar to the one i get with
ret = myprinter.setup(); in Qt3.

jacek
4th May 2006, 21:50
what I wanted is to display a window similar to the one i get with ret = myprinter.setup(); in Qt3.
Then try QPageSetupDialog.

impeteperry
5th May 2006, 02:55
Thanks. I am new to this and am is the learning process and am totally confused.. I would appreciate it if, using the code snippit in my original post, you wold show the code to do what the
ret = myprinter.setup(); did in Qt3.

Thanks

pete

jacek
5th May 2006, 12:13
I am new to this and am is the learning process and am totally confused.. I would appreciate it if, using the code snippit in my original post, you wold show the code to do what the did in Qt3.
It's something like:
#include <QPageSetupDialog>
...
QPrinter myprinter;
myprinter.setPageSize( QPrinter::Letter );
myprinter.setOrientation( QPrinter::Portrait );
myprinter.setColorMode( QPrinter::Color );
myprinter.setFullPage ( true );

QPageSetupDialog dialog( &myprinter, this );
if( dialog.exec() == QDialog::Accepted ) {
...
}

impeteperry
5th May 2006, 13:40
Thanks a whole lot. You gave me the clue I was lookng for. I forgot the "#include"
What I had was
QPrintDialog dialog(&myprinter, this);
if (dialog.exec() == QDialog::Accepted) but not the #Include.
This gives me the "dialog" I was looing for.

Life is simple when you know what you are doing. Now I can go away happy.

Thanks again.