#include <QApplication> #include <QPrinter> #include <QPrintDialog> #include <QPainter> int main(int argc, char *argv[]) { QApplication a(argc, argv); QString text =
"Test print"
; QPrinter printer; QPrintDialog *dialog = new QPrintDialog(&printer); dialog->setWindowTitle("Print Document"); if (dialog->exec() != QDialog::Accepted) return -1; QPainter painter; painter.begin(&printer); painter.drawText(100, 100, 500, 500, Qt::AlignLeft|Qt::AlignTop, text); painter.end(); return 0; }
https://stackoverflow.com/questions/11397683/how-to-print-text-file-to-printer-in-qt
===========================================================
ถ้าต้องการให้ print ทันที ก็ให้ตัด code ในส่วนที่เป็น dialog ออกไป
#include <QApplication>
#include <QPrinter>
#include <QPainter>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString text ="Test print";
QPrinter printer;
QPainter painter;
painter.begin(&printer);
painter.drawText(100, 100, 500, 500, Qt::AlignLeft|Qt::AlignTop, text);
painter.end();
return 0;
}
==============================================================
ลง driver printer hp ตามนี้
https://www.youtube.com/watch?v=va6PWYZScZk
ไม่มีความคิดเห็น:
แสดงความคิดเห็น