#include "mainwindow.h"
#include <QPainter>
#include <QPaintEvent>
#include <QPrinter>
#include <QMessageBox>
MainWindow
::MainWindow(QWidget *parent
) :{
move(0,0);
btn->adjustSize();
btn->move(100,15);
connect(btn,SIGNAL(clicked()),this,SLOT(btnClicked()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::btnClicked(){
bool ok;
printer.setOutputFileName("print.pdf");
ok=printer.isValid();
ok=painter.begin(&printer);
if(ok)
painter.drawRect(r);
ok=ok&&painter.end();
if(ok)
QMessageBox::information(this,
"",
"image printed on \"print.pdf\"");
else
QMessageBox::information(this,
"",
"Some error occurred!");
}
painter.drawRect(r);
}
#include "mainwindow.h"
#include <QPainter>
#include <QPaintEvent>
#include <QPrinter>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
btn = new QPushButton("doPdf", this);
move(0,0);
btn->adjustSize();
btn->move(100,15);
connect(btn,SIGNAL(clicked()),this,SLOT(btnClicked()));
}
MainWindow::~MainWindow()
{
}
void MainWindow::btnClicked(){
bool ok;
QRect r=QRect(10,10,80,50);
QPrinter printer;
QPainter painter;
printer.setOutputFileName("print.pdf");
ok=printer.isValid();
ok=painter.begin(&printer);
if(ok)
painter.drawRect(r);
ok=ok&&painter.end();
if(ok)
QMessageBox::information(this,"","image printed on \"print.pdf\"");
else
QMessageBox::information(this,"","Some error occurred!");
}
void MainWindow::paintEvent(QPaintEvent * ev){
QRect r=QRect(10,10,80,50);
QPainter painter(this);
painter.drawRect(r);
}
To copy to clipboard, switch view to plain text mode
Bookmarks