qtextedit

Can I have single line sized QTextEdit with simple html?

筅森魡賤 提交于 2020-03-02 12:18:31
问题 I need to display simple status row with text which will contain following styles: color bold italic QTextEdit can render simple HTML. But it also forcibly expands over multiple lines: Red background was added to emphasize the dimensions of the QTextEdit . Desired size is the size of one text line. How do I achieve that? 回答1: First of all, if you've simply used a QLabel , you'd not need to do anything special: it supports rich text format, and only takes as much space as necessary: #include

Display text from QLineEdit in a QTextEdit already containing some text and update it in real time

喜欢而已 提交于 2020-02-28 07:26:06
问题 What is the procedure to make a text being written in a QLineEdit widget, dynamically display inside a QTextEdit that already contains some text? For example, let us say that a QLineEdit asks for a name where one writes "John". Is it possible to display it in real time inside a QTextEdit containing : The name is + textFromQLineEdit + , age 24 ? The displayed text has to dynamically take into account the changes being made to the QLineEdit so that the user does not need to press a button or

PyQt5 - TypeError: signal has 0 argument(s) but 1 provided

寵の児 提交于 2020-01-30 03:28:27
问题 I am trying to redirect "sys.stdout" to QTextEdit , here is my code: class Communicate(QObject): printText = pyqtSignal() def write(self, text): self.printText.emit(str(text)) class UI(QWidget): def __init__(self, parent = None): QWidget.__init__(self) ... self.textedit = QTextEdit(self) self.textedit.setGeometry(400,20,220,300) self.c = Communicate() self.c.printText.connect(self.textedit.insertPlainText) sys.stdout = self.c if __name__ == "__main__": ... When I ran the code, I got TypeError

PyQt5 - TypeError: signal has 0 argument(s) but 1 provided

独自空忆成欢 提交于 2020-01-30 03:28:09
问题 I am trying to redirect "sys.stdout" to QTextEdit , here is my code: class Communicate(QObject): printText = pyqtSignal() def write(self, text): self.printText.emit(str(text)) class UI(QWidget): def __init__(self, parent = None): QWidget.__init__(self) ... self.textedit = QTextEdit(self) self.textedit.setGeometry(400,20,220,300) self.c = Communicate() self.c.printText.connect(self.textedit.insertPlainText) sys.stdout = self.c if __name__ == "__main__": ... When I ran the code, I got TypeError

qtextedit - resize to fit

旧巷老猫 提交于 2020-01-22 13:34:13
问题 I have a QTextEdit which act as "displayer" (editable to false). The text it displays is wordwrapped. Now I do wish to set the height of this textbox so that the text fits exactly (while also respecting a maximum height). Basically the widget (in the same vertical layout) below the layout should get as much space as possible. How can this be achieved most easily? 回答1: I found a pretty stable, easy solution using QFontMetrics ! from PyQt4 import QtGui text = ("The answer is QFontMetrics\n." "

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.

QTextEdit and colored bash-like output emulation

流过昼夜 提交于 2020-01-09 05:31:05
问题 I have an escape sequences in a text, like char const * text = "\e[1;33m" "some colored text" "\e[0m"; Which usually printed in terminal. But I want to forward this text in QTextEdit . What is the simpliest way to make such text in QTextEdit colored? How to perform a filtering of escape sequences, i.e. how replace its with proper text formatting? I think there is QSyntaxHighlighter -aided solution possible, but I don't know what to do with escape sequences itself and how to hide they from the

How to align QTextEdit text

邮差的信 提交于 2020-01-06 03:13:45
问题 How can I align this text? \t is not good. What I see (image) Expected result (image) 回答1: I had this problem once in the past. To solve the issue I used monospace font. To get everything aligned (fixed font width) I used these lines: // Use "monospaced" font: // ->insure left column alignment, as for the terminal // QFont font("monospace"); font.setPointSize(10); myQTextEdit->setCurrentFont(font); from my parent widget containing a QTextEdit child widget. 回答2: this line: QString str =