Hello there,
I know there are a lot of topics about QPrintPreviewDialog issues, I read a lot of them but it didn't help me so here I am. I need some explanations because I don't understand how it works.
I've got two QPushButtons that will call either the print preview or the print itself.
Here's my code so far:
//My printPreview slot
QPrintPreviewDialog preview(&printer, this);
preview.setWindowFlags ( Qt::Window );
preview.setWindowTitle("Aperçu avant impression");
connect(&preview,
SIGNAL(paintRequested
(QPrinter *)),
SLOT(Impression
(QPrinter *)));
//Impression is my print slot. When is paintRequested emitted exactly? I read the documentation but didn't understand.... preview.exec();
//My Print slot
painter.begin(p); //p is my QPrinter
double xscale = p->pageRect().width()/double(ui.Onglets->width());
double yscale = p->pageRect().height()/double(ui.Onglets->height());
double scale = qMin(xscale, yscale);
painter.translate(p->paperRect().x() + p->pageRect().width()/2, p->paperRect().y() + p->pageRect().height()/2); // to put my widget in the center of my page
painter.scale(scale, scale);
painter.translate(-width()/2, -height()/2);
ui.Onglets->render(&painter); //Onglets is a QTabWidget
//My printPreview slot
QPrinter printer(QPrinter::HighResolution);
QPrintPreviewDialog preview(&printer, this);
preview.setWindowFlags ( Qt::Window );
preview.setWindowTitle("Aperçu avant impression");
connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(Impression(QPrinter *))); //Impression is my print slot. When is paintRequested emitted exactly? I read the documentation but didn't understand....
preview.exec();
//My Print slot
QPainter painter;
painter.begin(p); //p is my QPrinter
double xscale = p->pageRect().width()/double(ui.Onglets->width());
double yscale = p->pageRect().height()/double(ui.Onglets->height());
double scale = qMin(xscale, yscale);
painter.translate(p->paperRect().x() + p->pageRect().width()/2, p->paperRect().y() + p->pageRect().height()/2); // to put my widget in the center of my page
painter.scale(scale, scale);
painter.translate(-width()/2, -height()/2);
ui.Onglets->render(&painter); //Onglets is a QTabWidget
To copy to clipboard, switch view to plain text mode
So far only a part of my window shows up in my preview dialog. This problem comes from my print slot or the print preview one?
Could you please explain to me how it works exactly?
Thanks in advance for your answers.
Bookmarks