Solved QPrinter - How to print a selected .txt file
-
Hi All,
I've been doing research on QPrinter/QPrintDialog/QPainter and I am getting extremely confused. A lot of the code that I am reading doesn't really pertain to me because they are printing directly from the GUI widgets (ui->textedit->print()).
Here is what I have so far on my code....
void MainGui::on_actionPrint_Telemetry_triggered() { QPrinter printer; QPrintDialog dialogp(&printer, this); dialogp.setWindowTitle(tr("Print Document")); if (dialogp.exec() != QDialog::Accepted) { return; } }
So, I would like to be able to have the user choose the file that they want to print. I already have a save function that is taking the data that I have and saving it to a .txt file. I'm sure I am just way overthinking this, but any help is appreciated!!
Thanks All,
Derek -
Hi
The easy way would to use
http://doc.qt.io/qt-5/qtextdocument.html
as it can directly print to printer object.
http://doc.qt.io/qt-5/qtextdocument.html#printthere is also the option of drawing the texts yourself but i get the feeling you just want to print
the text document as is ? -
Hey @mrjj ,
Thanks for your quick response! Yay, I can print!
And you are correct! I do just want to print :D
Thanks again for all of your help! This worked perfectly!!
Derek