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. Printing with qt5
Qt 6.11 is out! See what's new in the release blog

Printing with qt5

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.1k 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.
  • C Offline
    C Offline
    cupressus
    wrote on last edited by
    #1

    Hello,

    i have a simple qml application. Now i want to print a textfield content.
    Does anybody know where to find a complete sample code for doing that.

    I searched the web but i found nothing suitable.

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

      Hi
      QML cannot directly print as far as i know. You have to sent it to c++ side and do it there.
      https://forum.qt.io/topic/57861/solved-how-to-take-a-print-in-qml/14

      1 Reply Last reply
      2
      • C Offline
        C Offline
        cupressus
        wrote on last edited by
        #3

        @mrjj

        Hello, thank you for link. I used this example as template but i got my application not to run. I do not know how to handle this error message.

        Unbenannt.jpg

        B 1 Reply Last reply
        0
        • C cupressus

          @mrjj

          Hello, thank you for link. I used this example as template but i got my application not to run. I do not know how to handle this error message.

          Unbenannt.jpg

          B Offline
          B Offline
          Bonnie
          wrote on last edited by Bonnie
          #4

          @cupressus Hi, for this error message, you just need to include <QQmlContext> (I don't know qml though)

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cupressus
            wrote on last edited by
            #5

            Hi,

            many thanks. Works fine now.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cupressus
              wrote on last edited by
              #6

              it prints but print quality is terrible. How can i solve that.
              Unbenannt.jpg

              mrjjM 1 Reply Last reply
              0
              • C cupressus

                it prints but print quality is terrible. How can i solve that.
                Unbenannt.jpg

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @cupressus
                Ok that dont look right :)

                Try save image to a file and see how it looks to know if its something printer or
                the image really is that bad.

                void pr::print(QVariant data)
                {
                QImage img = qvariant_cast<QImage>(data);
                img.save(xxxx) <<<<<<<<<<<<<<<<<<<<< try save it
                QPrinter printer;
                QPrintDialog *dlg = new QPrintDialog(&printer,0);
                if(dlg->exec() == QDialog::Accepted) {
                QPainter painter(&printer);
                painter.drawImage(QPoint(0,0),img);
                painter.end();
                }
                }

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cupressus
                  wrote on last edited by
                  #8

                  i have found the error. I used a white font color because the text is shown on a grey background. I have now changed the text color to black and now everything looks fine.

                  1 Reply Last reply
                  1

                  • Login

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