qtextdocument

How to change the font and size of image in QTextDocument?

爱⌒轻易说出口 提交于 2021-01-29 06:44:21
问题 I want to print some text and image designed by qtdesigner. How could I change font and another format in QTextDocument ? from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport class Ui_MainWindow(object): def handlePrint(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QtWidgets.QDialog.Accepted: self.handlePaintRequest(dialog.printer()) def handlePreview(self): dialog = QtPrintSupport.QPrintPreviewDialog() dialog.paintRequested.connect(self.handlePaintRequest) dialog

Qt4/PyQt4 - Can not set the default font for QTextDocument

谁都会走 提交于 2021-01-28 18:41:49
问题 My code is like this: from PyQt4 import QtGui doc = QtGui.QTextDocument() d_font = QtGui.QFont('Times New Roman') doc.setDefaultFont(d_font) cur = QtGui.QTextCursor(doc) cur.insertText('sample text') writer = QtGui.QTextDocumentWriter() writer.setFormat(writer.supportedDocumentFormats()[1]) writer.setFileName('CV') writer.write(doc) The 'sample text' in the output is still 'Sans' on my computer rather than "Times New Roman'. I have made sure my computer has 'Times New Roman' font. I suspect

How to set painter of printer correctly?

落爺英雄遲暮 提交于 2020-08-10 19:17:37
问题 I'm printing a set of tables, each table should get its own page and could be long. The basics are working, but I don't get the footer painted. The problem is the footer will be painted in an extra document(s). According to the docs I must set the painter to the device. The device is painter, that's correct, but how do I set the painter to the correct Block? Or is it wrong to act this way? The goal is to use this document twice. 1st attempt is to print, the second a QTextDocument where I can

How to set painter of printer correctly?

岁酱吖の 提交于 2020-08-10 19:17:21
问题 I'm printing a set of tables, each table should get its own page and could be long. The basics are working, but I don't get the footer painted. The problem is the footer will be painted in an extra document(s). According to the docs I must set the painter to the device. The device is painter, that's correct, but how do I set the painter to the correct Block? Or is it wrong to act this way? The goal is to use this document twice. 1st attempt is to print, the second a QTextDocument where I can

How to set painter of printer correctly?

故事扮演 提交于 2020-08-10 19:17:01
问题 I'm printing a set of tables, each table should get its own page and could be long. The basics are working, but I don't get the footer painted. The problem is the footer will be painted in an extra document(s). According to the docs I must set the painter to the device. The device is painter, that's correct, but how do I set the painter to the correct Block? Or is it wrong to act this way? The goal is to use this document twice. 1st attempt is to print, the second a QTextDocument where I can

How to set the size of image and text inside QTextEdit using QTextDocumentFragment

亡梦爱人 提交于 2020-01-15 12:15:13
问题 Following my previous post I am implementing a command log using QTextEdit . The way it works is that every time the user interacts with the user interface the action is recorded inside a QTextEdit Command Log shown below. I successfully associate an image to every action (e.g. pushing a button, checking a box etc) but as you see in the print screen below the image is not resizing and everytime the user does something, instead of having an additional line, the image is put next to the other:

How to access QTextDocument pages

旧巷老猫 提交于 2020-01-13 05:45:11
问题 I am trying to build an application that would display rich text documents in paginated fashion - more or less like MS Word does. For now, I would like to have only one page displayed at a time. From this question I have learned that I need to represent the document by QTextDocument. While the author of the question focuses more on the view representation, I would like to learn about accessing document data in paginated fashion. I can see that the class has methods such as setPageSize() and

Qt ignores CSS in QTextDocument

寵の児 提交于 2020-01-11 09:51:39
问题 Here is a small snippet of my code, I don't know why but Qt is ignoring the css. QTextDocument *mTextDocument = new QTextDocument(0); QTextEdit *textEdit = new QTextEdit(0); mTextDocument->setDefaultStyleSheet(QString::fromUtf8("body{background-color: rgb(0,111,200);}")); QTextCursor *_cursor = new QTextCursor(mTextDocument); textEdit->setDocument(mTextDocument); _cursor->insertBlock(); _cursor->insertHtml("<html><body><p>Hello world</p></body></html>"); textEdit->show(); I'm using Qt 4.8.

Two colours text in QPushButton

限于喜欢 提交于 2019-12-29 08:37:04
问题 I need a QPushButton with two colors in the text. I found a solution with a html code in QTextDocument and it's working. But I need center align and the html code isn't working. QTextDocument Text; Text.setHtml("<p align=center><font>Button</font><br/><font color=yellow>1</font></p>"); QPixmap pixmap(Text.size().width(), Text.size().height()); pixmap.fill( Qt::transparent ); QPainter painter(&pixmap); Text.drawContents(&painter, pixmap.rect()); QIcon ButtonIcon(pixmap); ui->toolButton-

Populate a QTextDocument from a .odt file

大城市里の小女人 提交于 2019-12-20 03:39:10
问题 I am writing a rich text editor using C++ and Qt. For now, I would like it to support (at least) the .odt format. I found QTextDocumentWriter for writing the contents of the QTextDocument to a file, but I can't seem to find anything to read that back into the QTextDocument, which obviously makes saving it sort of useless in the first place. So the question is, how do I load an .odt document into a QTextDocument? 回答1: Qt does not currently support the ODT format. Okular has code that does