本文整理匯總了Python中PyQt4.QtGui.QTextDocument方法的典型用法代碼示例。如果您正苦於以下問題:Python QtGui.QTextDocument方法的具體用法?Python QtGui.QTextDocument怎麽用?Python QtGui.QTextDocument使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.QtGui
的用法示例。
在下文中一共展示了QtGui.QTextDocument方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: print_result
# 需要導入模塊: from PyQt4 import QtGui [as 別名]
# 或者: from PyQt4.QtGui import QTextDocument [as 別名]
def print_result(self):
if "HTML" in self.result:
data=QtCore.QFile("ar/style.css");
if (data.open(QtCore.QFile.ReadOnly)):
mySTYLE_SHEET=QtCore.QTextStream(data).readAll();
## text=unicode(text);
else:
mySTYLE_SHEET=u"""
body {
direction: rtl;
font-family: Traditional Arabic, "Times New Roman";
font-size: 16pt;
}
"""
document = QtGui.QTextDocument("")
document.setDefaultStyleSheet(mySTYLE_SHEET)
self.result["HTML"]=u"<html dir=rtl><body dir='rtl'>"+self.result["HTML"]+"</body></html>"
document.setHtml(self.result["HTML"]);
printer = QtGui.QPrinter()
dlg = QtGui.QPrintDialog(printer, self.centralwidget)
if dlg.exec_() != QtGui.QDialog.Accepted:
return
self.ResultVocalized.print_(printer)
else:
QtGui.QMessageBox.warning(self.centralwidget,U"خطأ",
u"لا شيء يمكن طبعه.")
示例2: init_print
# 需要導入模塊: from PyQt4 import QtGui [as 別名]
# 或者: from PyQt4.QtGui import QTextDocument [as 別名]
def init_print(self, linenos=True, style="default"):
app = QApplication(sys.argv) # noqa
doc = QTextDocument()
doc.setHtml(
self.highlight_file(linenos=linenos, style=style)
)
printer = QPrinter()
printer.setOutputFileName(self.pdf_file)
printer.setOutputFormat(QPrinter.PdfFormat)
page_size_dict = {"a2": QPrinter.A2, "a3": QPrinter.A3, "a4": QPrinter.A4}
printer.setPageSize(page_size_dict.get(self.size.lower(), QPrinter.A4))
printer.setPageMargins(15, 15, 15, 15, QPrinter.Millimeter)
doc.print_(printer)
logging.info("PDF created at %s" % (self.pdf_file))
示例3: __init__
# 需要導入模塊: from PyQt4 import QtGui [as 別名]
# 或者: from PyQt4.QtGui import QTextDocument [as 別名]
def __init__(self, parent=None):
super(HTMLDelegate, self).__init__(parent)
self.doc = qg.QTextDocument(self)
示例4: createWidget
# 需要導入模塊: from PyQt4 import QtGui [as 別名]
# 或者: from PyQt4.QtGui import QTextDocument [as 別名]
def createWidget(self, style, listWidget, chat_msg,uin,flag=0,g_sender=None):
self.listWidgetItem = QtGui.QListWidgetItem(listWidget)
self.listWidgetItem.setSizeHint(QtCore.QSize(0, 50))
self.widget = QtGui.QWidget()
self.graphicsView = QtGui.QGraphicsView(self.widget)
self.label = QtGui.QTextBrowser(self.widget)
self.label.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
orient=''
if flag==0:
ruin=uin
else:
ruin=g_sender
print 'img senderuin:',ruin
if style == 0:
self.widget.setGeometry(QtCore.QRect(0, 10, 455, 50))
self.graphicsView.setGeometry(QtCore.QRect(5, 5, 60, 60))
self.graphicsView.setScene(self.createImg(ruin,flag,g_sender))
self.graphicsView.resize(50,50)
self.label.setGeometry(QtCore.QRect(50, 5, 390, 50))
orient='left'
elif style == 1:
self.widget.setGeometry(QtCore.QRect(0, 10, 455, 50))
self.graphicsView.setGeometry(QtCore.QRect(392, 5, 60, 60))
self.graphicsView.setScene(self.createImg(ruin,flag,g_sender))
self.graphicsView.resize(50,50)
self.label.setGeometry(QtCore.QRect(10, 5, 390, 50))
orient='right'
# msg edit
if flag==1:
nick=self.groupInfo[uin][g_sender]['nick']
if flag==2:
nick=self.discussInfo[uin][g_sender]['nick']
if flag==1 or flag==2:
chat_msg=u'<p><b>'+nick+'</b></p><p>'+chat_msg+'</p>'
content = u'''
<html><body><p align="'''+orient+'''"> ''' + chat_msg + '''</p></body></html>
'''
doc = QtGui.QTextDocument(self.label)
doc.setHtml(content)
self.label.setDocument(doc)
# resize
size = max(self.label.document().size().height() + 5, 50)
self.listWidgetItem.setSizeHint(QtCore.QSize(445, size))
self.widget.resize(455, size)
self.label.resize(380, size)
return self.listWidgetItem, self.widget