小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Python調(diào)用打印機參考例子

 GTY_TSG 2021-07-27
from PyQt5.QtWidgets import (QApplication, QWidget, QTableWidget,QPushButton,
                             QVBoxLayout,
                            QTableWidgetItem)
from PyQt5.QtGui import  QPixmap, QPainter, QImage, QTextDocument
from PyQt5.QtPrintSupport import  QPrinter, QPrintDialog, QPrintPreviewDialog
from PyQt5.QtCore import QRect, QPoint, QSize ,  Qt
# 有預覽框<br># 908204694@qq.com<br>#
def on_htmlButton_clicked():
    printer =QPrinter(QPrinter.HighResolution)
    #/* 打印預覽 */
    preview =QPrintPreviewDialog(printer,widget )  
    preview.paintRequested.connect(printHtml)
     
    #
    #   顯示 預覽框
    #
    #preview.exec()
    preview.exec_()
def printHtml(printer):
    html = '''<html>
    <head></head>
    <body>
        <h1>55555</h1><b>bold</b><h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b><h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b><h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b><h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
        <h1>55555</h1><b>bold</b>
    </body>
    </html>'''
    textDocument = QTextDocument()
    textDocument.setHtml(html)
    #textDocument.print(printer)
    textDocument.print_(printer)
    
def on_picButton_clicked():
    printer =QPrinter(QPrinter.HighResolution)
#/* 打印預覽 */
    preview =QPrintPreviewDialog(printer,widget )  
    '''
     * QPrintPreviewDialog類提供了一個打印預覽對話框,里面功能比較全,
     * paintRequested(QPrinter *printer)是系統(tǒng)提供的,
     * 當preview.exec()執(zhí)行時該信號被觸發(fā),
     * plotPic(QPrinter *printer)是用戶自定義的槽函數(shù),圖像的繪制就在這個函數(shù)里。
    '''
    preview.paintRequested.connect(plotPic)
    preview.exec()#/* 等待預覽界面退出 */
def  plotPic(printer):
    
    
    painter =QPainter(printer);
    image = QPixmap()
    image=widget.grab(QRect( QPoint( 0, 0 ),
                                            QSize( widget.size().width(),
                                                        widget.size().height()
                                                    )
                                        )
                                )# /* 繪制窗口至畫布 */
   #QRect
    rect = painter.viewport();
   #QSize
    size = image.size();
    size.scale(rect.size(), Qt.KeepAspectRatio)#     //此處保證圖片顯示完整
    painter.setViewport(rect.x(), rect.y(),size.width(), size.height());
    painter.setWindow(image.rect());
    painter.drawPixmap(0,0,image); #/* 數(shù)據(jù)顯示至預覽界面 */
import sys
app = QApplication(sys.argv)
tablewidget = QTableWidget()
## 設置列數(shù)
tablewidget.setColumnCount(4)
tablewidget.horizontalHeader().setDefaultSectionSize(150)
## QStringList在PyQt5
header= ['name', 'last modify time','type''size']
tablewidget.setHorizontalHeaderLabels(header)
tablewidget.insertRow(0)
tablewidget.insertRow(0)
pItem1 =  QTableWidgetItem('aa' )
pItem2 =  QTableWidgetItem('bb' )
pItem3 =  QTableWidgetItem('cc' )
pItem4 =  QTableWidgetItem('dd' )
tablewidget.setItem( 0, 0, pItem1 )
tablewidget.setItem( 0, 1, pItem2 )
tablewidget.setItem( 0, 2, pItem3 )
tablewidget.setItem( 0, 3, pItem4 )
tablewidget.setMinimumSize(800, 600)
button = QPushButton('打印界面')
button.clicked.connect(on_picButton_clicked)
button_txt = QPushButton('打印文字')
button_txt.clicked.connect(on_htmlButton_clicked)
widget = QWidget()
layout = QVBoxLayout(widget)
layout.addWidget(button)
layout.addWidget(button_txt)
layout.addWidget(tablewidget)
widget.show()
sys.exit(app.exec_())

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多