Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7045897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:35:10+00:00 2026-05-28T02:35:10+00:00

Background This is only my second PyQt4 project. Developing a Windows app that has

  • 0

Background

This is only my second PyQt4 project. Developing a Windows app that has INVOICE management as one of its components.

Question

I need suggestions on how to successfully create a list that can be cleanly printed even if it spans across multiple pages.
Something like QTableView or QTableWidget.

UI Details

Few Header Lines (Client info, invoice number etc) followed by rows of:
| SKU # | NAME | DESCRIPTION | QUANTITY | PRICE
With some subtotals and grand totals on the bottom.

Print Functionality

When [Ctrl]+P is pressed or File–>Print is selected, system printer dialog should pop-up allowing you to print the invoice that can span multiple Letter sized pages.
Optionally, is there a quick and easy way to implement a print preview?

I don’t want to spend 3 days using QTableWidget + QPrinter only to find out that it cannot do what I need it to do. Looking for help/tips/insight from your past experience that will save me time and effort.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:35:10+00:00Added an answer on May 28, 2026 at 2:35 am

    I pretty sure everything you want to achieve is possible using PyQt4.

    I have added a basic script below which demonstrates the functionality you’re after. The format of the printed table is very crude, but you could easily achieve something fancier by using html instead of the simple text-table I’ve used.

    from PyQt4 import QtGui, QtCore
    
    class Window(QtGui.QWidget):
        def __init__(self):
            QtGui.QWidget.__init__(self)
            self.setWindowTitle(self.tr('Document Printer'))
            self.table = QtGui.QTableWidget(200, 5, self)
            for row in range(self.table.rowCount()):
                for col in range(self.table.columnCount()):
                    item = QtGui.QTableWidgetItem('(%d, %d)' % (row, col))
                    item.setTextAlignment(QtCore.Qt.AlignCenter)
                    self.table.setItem(row, col, item)
            self.table.setHorizontalHeaderLabels(
                'SKU #|NAME|DESCRIPTION|QUANTITY|PRICE'.split('|'))
            self.buttonPrint = QtGui.QPushButton('Print', self)
            self.buttonPrint.clicked.connect(self.handlePrint)
            self.buttonPreview = QtGui.QPushButton('Preview', self)
            self.buttonPreview.clicked.connect(self.handlePreview)
            layout = QtGui.QGridLayout(self)
            layout.addWidget(self.table, 0, 0, 1, 2)
            layout.addWidget(self.buttonPrint, 1, 0)
            layout.addWidget(self.buttonPreview, 1, 1)
    
        def handlePrint(self):
            dialog = QtGui.QPrintDialog()
            if dialog.exec_() == QtGui.QDialog.Accepted:
                self.handlePaintRequest(dialog.printer())
    
        def handlePreview(self):
            dialog = QtGui.QPrintPreviewDialog()
            dialog.paintRequested.connect(self.handlePaintRequest)
            dialog.exec_()
    
        def handlePaintRequest(self, printer):
            document = QtGui.QTextDocument()
            cursor = QtGui.QTextCursor(document)
            table = cursor.insertTable(
                self.table.rowCount(), self.table.columnCount())
            for row in range(table.rows()):
                for col in range(table.columns()):
                    cursor.insertText(self.table.item(row, col).text())
                    cursor.movePosition(QtGui.QTextCursor.NextCell)
            document.print_(printer)
    
    if __name__ == '__main__':
    
        import sys
        app = QtGui.QApplication(sys.argv)
        window = Window()
        window.resize(640, 480)
        window.show()
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

background: url({{ MEDIA_URL }}/bg.jpg); That does not work, because this Django template function only
Background This question is in two parts. I have a one-way WCF operation hosted
Background this post explains how one can consume extension methods in Powershell http://community.bartdesmet.net/blogs/bart/archive/2007/09/06/extension-methods-in-windows-powershell.aspx Compare
I have css declaration like this #first, #second, #third { font-size:1em; background: url('path/to/image') no-repeat;
A client has asked that their home page begin blank (only the logo and
I made this tiny video (please ignore if background noises) http://www.screenr.com/Qvts its 13 seconds
Background: This question relates to versions of Delphi below 2009 (ie without Unicode support
I have this background, the css code is: body { background: #FFF url('images/bg.png') no-repeat
Please refer to this background question. After constructing this COUNT, how would I then
For the background to this question, see How to I serialize a large graph

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.