c++ - Print Preview in Qt -
i want preview page or want have print preview. preview window opening contents of qt window not comming in it. code print preview follows:
void user::on_actionprintpreview_triggered() { qprinter printer(qprinter::highresolution); qprintpreviewdialog preview(&printer, this); connect(&preview, signal(paintrequested(qprinter *)), this, slot(print(qprinter *))); preview.exec(); } void user::print(qprinter *printer) { // print page qpainter painter(printer); int w = printer->pagerect().width(); int h = printer->pagerect().height(); qrect page(0, 0, w, h); qfont font = painter.font(); font.setpixelsize((w+h)/100); painter.setfont(font); painter.drawtext(page, qt::alignbottom | qt::alignright, qdatetime::currentdatetime(). tostring(qt::defaultlocaleshortdate)); page.adjust(w/20, h/20, -w/20, -h/20); }
how can content of qt window in it. doing wrong. please me out solve this.
if want print contents of dialog or widget, print
slot should like:
void user::print(qprinter * printer) { qpainter painter(printer); painter.setwindow(this->rect()); this->render(&painter); }
Comments
Post a Comment