Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPrinter - How to print a selected .txt file
Forum Updated to NodeBB v4.3 + New Features

QPrinter - How to print a selected .txt file

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    d_ly56
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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#print

      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 ?

      1 Reply Last reply
      3
      • D Offline
        D Offline
        d_ly56
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved