Results 1 to 4 of 4

Thread: Print text on the LineEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2016
    Posts
    2
    Qt products
    Qt5

    Default Print text on the LineEdit

    Hello everyone I am new to this forum and I enjoy a bit of time with QT 5.7 I've created a first graphical interface, but now I have a problem where I'm stuck printing LineEdit.
    I post the code I was able to print in the textEdit text but if you want to print in a LineEdit simply replacing the previous me error:


    void MainWindow:n_actionPrint_triggered()
    {
    QPrinter printer;
    printer.setPrinterName("desierd printer name");
    QPrintDialog dialog(&printer,this);
    if(dialog.exec() == QDialog::Rejected) return;
    ui->textEdit->print(&printer);
    }


    If as I said now I replace the textEdit the LineEdit me error will be changed because of something that row but do not know how ...

    And also I should print various LineEdit not only so do not know even then how to assemble the various LineEdit because they are printed in the correct position.

    If anyone has a solution thank you in advance.

  2. #2
    Join Date
    Dec 2016
    Posts
    46
    Thanks
    20
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Print text on the LineEdit

    I am not quite sure what you mean. I am a beginner myself but I wonder, can you first get the text from LineEdit and then send it to the printer function? Basically dividing the process into smaller steps to diagnose where the problem occurs.


    Qt Code:
    1. #include <QDebug>
    2. void MainWindow::on_actionPrint_triggered()
    3. {
    4. // actionPrint triggered
    5. qDebug() << "actionPrint triggered."
    6.  
    7. // instanciate new printer
    8. QPrinter printer;
    9. qDebug() << "Printer instanciated."
    10.  
    11. // Set name
    12. printer.setPrinterName("Desired printer name");
    13. qDebug() << "Printer name set: " + printer.name;
    14.  
    15. // Instanciate new QPrintDialog
    16. QPrintDialog dialog(&printer,this);
    17.  
    18. // Dialog
    19. if(dialog.exec() == QDialog::Rejected)
    20. {
    21. qDebug() << "QDialog rejected!";
    22. return;
    23. }
    24.  
    25. // get text from LineEdit
    26. QString toPrint = ui->lineEdit->text().toString();
    27. qDebug() << "LineEdit text retreived:\n" + toPrint;
    28.  
    29. // Print text from LineEdit
    30. toPrint->print(&printer);
    31. qDebug() << "Text print function called.";
    To copy to clipboard, switch view to plain text mode 

    Maybe "QString toPrint" isn't what you should end up using in the end, you might change it to QDocument or something else, I amnot quite sure really since I have never worked with those classes. I just thought that having the qDebug telling you what is going on might help you narrow down your your problem occurs.

Similar Threads

  1. Replies: 2
    Last Post: 25th September 2014, 01:24
  2. Replies: 7
    Last Post: 5th February 2014, 11:20
  3. how to get the text from a LineEdit using QT??
    By Soumya Somasekhar Ram in forum Qt Programming
    Replies: 11
    Last Post: 11th September 2013, 13:43
  4. send text of lineedit
    By akhilteja in forum Newbie
    Replies: 1
    Last Post: 23rd August 2013, 09:53
  5. print text in the lineEdit control from string
    By rk0747 in forum Qt Programming
    Replies: 2
    Last Post: 6th February 2010, 08:48

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.