Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to prevent page number from printing

How to prevent page number from printing

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 562 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.
  • K Offline
    K Offline
    kumar80
    wrote on last edited by
    #1

    When I run the below code at the the end it prints the page number. Is there a way to prevent that from happening

    from PySide6.QtGui import (
        QPageSize,
        QPageLayout,
        QTextBlockFormat,
        QTextCursor,
        QTextDocument,
        QTextFormat,
    )
    from PySide6.QtWidgets import QApplication
    from PySide6.QtPrintSupport import QPrinter, QPrintPreviewDialog
    
    
    app = QApplication()
    printer = QPrinter(QPrinter.HighResolution)
    dialog = QPrintPreviewDialog(printer)
    
    
    def handle_paint_requested(printer):
        document = QTextDocument()
        cursor = QTextCursor(document)
        blockFormat = QTextBlockFormat()
        text=open('sampletext.txt').read()
        cursor.insertBlock(blockFormat)
        cursor.insertText(text)
        document.print_(printer)
    dialog.paintRequested.connect(handle_paint_requested)
    dialog.exec()
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Set the document page size to a valid value.

      For the reasons, see the code of the QTextDocument::print function.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      K 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Set the document page size to a valid value.

        For the reasons, see the code of the QTextDocument::print function.

        K Offline
        K Offline
        kumar80
        wrote on last edited by
        #3

        @SGaist I am creating a billing application and the bill size is a custom size (10 x 6 inches). When you say set page size to a valid value. How would I go about setting this in context of custom size.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The pageSize property says that the point is 1/72 of an inch when printing.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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