Qt World Summit: Register Today!

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)

    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,

  • Lifetime Qt Champion

    The easy way would to use
    as it can directly print to printer object.

    there 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!!

Log in to reply