qtextedit

How to set number of lines for an QTextEdit?

▼魔方 西西 提交于 2019-12-03 01:59:38
I use a QTextEdit for some inputs. But I want to adjust the height of the box. Can I set the height based on the number of lines I want to have visible at a time? If you use QPlainTextEdit , something like this should do the trick: void SetHeight (QPlainTextEdit* edit, int nRows) { QFontMetrics m (edit -> font()) ; int RowHeight = m.lineSpacing() ; edit -> setFixedHeight (nRows * RowHeight) ; } You might want to add two or three pixels as margin; experiment will tell. Improving the accepted answer about QPlainTextEdit . In addition to lineSpacing , value for setFixedHeight should contain: 2

How to update a QTextEdit in real-time

左心房为你撑大大i 提交于 2019-12-02 15:31:51
问题 i have one UI with QtextEdit, (1) i want to update QtextEdit and main UI can display realtime and no stuck. when use sleep ,not work as i want. (2) i want have make one function and pass parameter to it, and the QtestEdit can update display real time self.pButton_torun.clicked.connect(self.mytodo) def mytodo(self): self.progress_textEdit.append(u"==== 20 % first step finish") #after 2 sec self.progress_textEdit.append(u"==== 40 % second step finish") #after 2 sec self.progress_textEdit.append

Semi-transparent highlights using PySide and QTextEdit

不羁的心 提交于 2019-12-02 07:09:24
问题 I've created a QTextEdit object. The code below adds randomly colored highlights to the currently selected text. I need the highlights to be semi-transparent so I can see highlights layered upon each other. Using "setAlpha" does not appear to do anything. How can I set the alpha for the highlight or otherwise obtain semi-transparency? # Define cursor & span self.cursor = self.textdoc.textCursor() self.selstart = self.cursor.selectionStart() self.selend = self.cursor.selectionEnd() self

Semi-transparent highlights using PySide and QTextEdit

烂漫一生 提交于 2019-12-01 23:36:06
I've created a QTextEdit object. The code below adds randomly colored highlights to the currently selected text. I need the highlights to be semi-transparent so I can see highlights layered upon each other. Using "setAlpha" does not appear to do anything. How can I set the alpha for the highlight or otherwise obtain semi-transparency? # Define cursor & span self.cursor = self.textdoc.textCursor() self.selstart = self.cursor.selectionStart() self.selend = self.cursor.selectionEnd() self.seltext = self.cursor.selectedText() # Create random color r = randint(0,255) g = randint(0, 255) b = randint

Qt ignores CSS in QTextDocument

旧时模样 提交于 2019-12-01 21:43:37
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. Your document already has html and body tags, so they are simply ignored when they are found in

How to change current line format in QTextEdit without selection?

我是研究僧i 提交于 2019-12-01 21:33:40
there! I want to find out how to change current line format in QTextEdit? In the document I read that "Formatting can be applied to the current text document using the setCharFormat(), mergeCharFormat(), setBlockFormat() and mergeBlockFormat() functions. If the cursor has no selection, current block format will be changed." But in my application, the current block in which cursor is couldn't be changed. May I miss something? Then how could I change current block format which has no selection? Here is my code: QTextCursor cursor = this->textCursor(); QTextBlockFormat blockFmt; blockFmt

Remove a line/block from QTextEdit

十年热恋 提交于 2019-12-01 17:49:39
I'm struggling with block/line removal from QTextEdit . Code below should(?) work but it ends up in infinite loop for some unknown to me reason. I have a suspicion that next() and previous() are not welcome if QTextDocument is being edited. QTextBlock block = document()->begin(); while (block.isValid()) { if (to_do_or_not_to_do(block)) { QTextCursor cursor(block); cursor.select(QTextCursor::BlockUnderCursor); cursor.removeSelectedText(); } block = block.next(); } Iterating using QTextDocument::findBlockByNumber() and deleting block in the same way as above didn't worked either. I would

How to highlight a string of text within a QTextEdit

柔情痞子 提交于 2019-12-01 06:03:13
I'm a student programmer currently developing an application for work using Qt4. I am building an equation editor and I'm having issues attempting to highlight a string within my QTextEdit field. I have a function that parses through the QTextEdit string and returns an a start and end integer of where an error is located. My original strategy was to use HTML tags at these two points to highlight the error. Unfortunately there appears to be an issue with html tagging and the equation syntax. What I think I need is a strategy that relies on Qt's library to set a background color between these

Resizing QT's QTextEdit to Match Text Height: maximumViewportSize()

旧巷老猫 提交于 2019-11-30 23:09:01
问题 I am trying to use a QTextEdit widget inside of a form containing several QT widgets. The form itself sits inside a QScrollArea that is the central widget for a window. My intent is that any necessary scrolling will take place in the main QScrollArea (rather than inside any widgets), and any widgets inside will automatically resize their height to hold their contents. I have tried to implement the automatic resizing of height with a QTextEdit, but have run into an odd issue. I created a sub

QTextEdit. How to select text manually?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 18:15:53
There are functions like textEdit->textCursor()->selectionStart() and textEdit->textCursor()->selectionEnd() , but there are no functions setSelectionStart , setSelectionEnd . Is there any way to select some part of text manually? QTextCursor c = textEdit->textCursor(); c.setPosition(startPos); c.setPosition(endPos, QTextCursor::KeepAnchor); textEdit->setTextCursor(c); This piece of code moves the cursor to the start position of the selection using setPosition , then moves it to the end of the selection, but leaves the selection anchor at the old position by specifying a MoveMode as the second