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. How to print the current tab on pressing a Push Button?

How to print the current tab on pressing a Push Button?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.9k Views
  • 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.
  • P Offline
    P Offline
    Piyush
    wrote on last edited by Piyush
    #1

    I need to print the current tab on pressing the push button. Also, I need to add functionality wherein after the button is pressed, the UI would ask for print or save in PDF.

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

      Hi
      You can use the print class for that
      http://doc.qt.io/qt-5/qprinter.html

      example of use
      https://stackoverflow.com/questions/45467942/how-can-i-print-a-qwidget-in-qt

      P 1 Reply Last reply
      1
      • mrjjM mrjj

        Hi
        You can use the print class for that
        http://doc.qt.io/qt-5/qprinter.html

        example of use
        https://stackoverflow.com/questions/45467942/how-can-i-print-a-qwidget-in-qt

        P Offline
        P Offline
        Piyush
        wrote on last edited by
        #3

        @mrjj Thanks for the help. I am unable to print the whole QDialog in a single page. In fact I have changed the orientation, margins and fullpage.

        mrjjM 1 Reply Last reply
        0
        • P Piyush

          @mrjj Thanks for the help. I am unable to print the whole QDialog in a single page. In fact I have changed the orientation, margins and fullpage.

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

          @Piyush
          ok, is that a question or ?

          You can scale it to fit one page. or that is to compressed to read ?

          Its hard(er) to print image over multiple pages.

          P 1 Reply Last reply
          0
          • mrjjM mrjj

            @Piyush
            ok, is that a question or ?

            You can scale it to fit one page. or that is to compressed to read ?

            Its hard(er) to print image over multiple pages.

            P Offline
            P Offline
            Piyush
            wrote on last edited by
            #5

            @mrjj I need to print a whole tab in a single A4 page. But the printer is giving print displaying partial tab. So How can I do it?

            mrjjM 1 Reply Last reply
            0
            • P Piyush

              @mrjj I need to print a whole tab in a single A4 page. But the printer is giving print displaying partial tab. So How can I do it?

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

              @Piyush
              Hi
              You might need to scale the image so it fits the page.

              P 1 Reply Last reply
              0
              • mrjjM mrjj

                @Piyush
                Hi
                You might need to scale the image so it fits the page.

                P Offline
                P Offline
                Piyush
                wrote on last edited by
                #7

                @mrjj Hi,
                I tried doing it, but still there is only partial print of tab. Is there any way by which I can pass the current tab in the print function? This is the code I am using:
                printer = QtPrintSupport.QPrinter()
                printer.setPageOrientation(1)
                printer.PrinterMode(2)
                printer.Unit(0)
                #printer.setFullPage(True)
                printer.setPageMargins(0,0,0,0,printer.Millimeter)
                painter = QtGui.QPainter()
                painter.begin(printer)
                screen = self.grab()
                painter.drawPixmap(0,0, screen)
                painter.end()

                mrjjM 1 Reply Last reply
                0
                • P Piyush

                  @mrjj Hi,
                  I tried doing it, but still there is only partial print of tab. Is there any way by which I can pass the current tab in the print function? This is the code I am using:
                  printer = QtPrintSupport.QPrinter()
                  printer.setPageOrientation(1)
                  printer.PrinterMode(2)
                  printer.Unit(0)
                  #printer.setFullPage(True)
                  printer.setPageMargins(0,0,0,0,printer.Millimeter)
                  painter = QtGui.QPainter()
                  painter.begin(printer)
                  screen = self.grab()
                  painter.drawPixmap(0,0, screen)
                  painter.end()

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

                  @Piyush

                  Hi
                  I dont see any scaling ?

                  painter.drawPixmap(0,0, screen) just seem to draw the image as is.

                  if you do
                  painter.drawPixmap(0,0, screen.scaled(screen.width()/2, screen.height() /2 ) )
                  it should draw in half the size
                  its c++ syntax. im not python user but should be pretty close.

                  1 Reply Last reply
                  0

                  • Login

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