qplaintextedit

qt plaintextedit change message color

ε祈祈猫儿з 提交于 2020-06-28 07:38:44
问题 I'm trying to color a text depending on message, i tried a lot of stuff but they change all text color not just the message that i need , exactly that one that's an error. if(Something) text = tr(""); if(SomethingElse) text = tr(""); ui->plainText->appendPlainText(text); 回答1: From Qt. doc. about QPlainTextEdit: Text can be formatted in a limited way, either using a syntax highlighter (see below), or by appending html-formatted text with appendHtml(). In the case of OP, I would recommend the

Saving text from QPlainTextEdit by QFileDialog and creating .txt file

纵然是瞬间 提交于 2020-01-06 05:30:14
问题 I have troubles with saving note(text from QPlainTextEdit). I need only saving in txt format. After typing text and clicking button program displays error 'expected string or bytes-like object not nonetype'.Notepad's program starts from class fileeki till class fileush. I use Python 3.7, PyQt5 and QtDesigner for creating interface.Opening works well, but not saving.Please download all elements of my project. Also there is modules, which you must install.Thanks for trying. import sys from

Display terminal output with tqdm in QPlainTextEdit

淺唱寂寞╮ 提交于 2020-01-04 05:33:30
问题 I'm trying to find a way of getting, along with other prints, the result/evolution of a progress bar in a pyqt application, for example in a QPlainTextEdit widget. The problem I'm facing, is that progress bars can use some more advanced carriage return, or even more advanced cursor positionning that are mostly not supported by treams. I've tried io.StringIO , but the \r is kept literal. import io from tqdm import tqdm s = io.StringIO() for i in tqdm(range(3), file=s): sleep(.1) output: s

Qt Clear Undo History in a QTextEdit/QPlainTextEdit?

五迷三道 提交于 2020-01-02 04:54:09
问题 I have a QPlainTextEdit and I'm building a progress dialog for it when opening large files. Rather than using setText, I want to add one line of text at a time by using QTextCursor.insertText. The problem is that when I do it this way, I can undo each line that was added... is there a way to clear the undo history? 回答1: Use QTextDocument::clearUndoRedoStacks. Code: editor->document()->clearUndoRedoStacks(); // default clears both See docs if you want to clear just undo. Also, it's good idea

QPlainTextEdit text and increase filename in new line in the window

走远了吗. 提交于 2019-12-24 19:13:40
问题 In my script I have a QPlainTextEdit window , when I run my pushbutton script printing a line in my window with ---projectname-seg(Segment)-group_name---, My problem is: when I run my script line is added, when I run it again is added to but I would like to increase my "Seg" in my second -def Rev_Text, each time when I run my function, like new_name change+1 each time when I run my function. I add a new line to my line_list but I can't extract last line and get only "seg element. I would like

Transparently get backspace event in PyQt

萝らか妹 提交于 2019-12-20 03:41:27
问题 I want to detect when backspace is pressed in a QPlainTextEdit widget. I have the following code: def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Backspace: print("Backspace pressed") (in a class inherited from QPlainTextEdit) The problem is that now pressing backspace (or any other character key) does not insert the character into the text box. I could check for every key and do it that way, however, especially with large files, removing the last character could be

Hiding text with QSyntaxHighlighter

此生再无相见时 提交于 2019-12-14 00:58:10
问题 Problem: I want to implement a text editing widget for text with additional tags. I'd like some tags to be invisible in some cases so that they do not distract the user. Environment: I'm using PyQt and prefer to use QPlainTextWidget and QSyntaxHighlighter . Approach: With QSyntaxHighlighter I can set QTextCharFormat for the strings which match my requirement. QTextCharFormat has gives me all font properties like size, colors, etc. but: I haven't found a option to hide the text or reduce its

Dedenting function in QPlainTextEdit causes segfault if last line is involved

a 夏天 提交于 2019-12-13 02:08:11
问题 I'm working on a source code editor that should have smart indent/dedent behaviour. However, my dedenting method seems to be causing a segmentation fault. I'd be very pleased if someone could work out why. Here's a minimal example: #!/usr/bin/env python import sip sip.setapi('QString', 2) sip.setapi('QVariant', 2) from PyQt4 import QtGui from PyQt4.QtCore import Qt class Editor(QtGui.QPlainTextEdit): def keyPressEvent(self, event): key = event.key() if key == Qt.Key_Backtab: cursor = self

QTextCursor and beginEditBlock

筅森魡賤 提交于 2019-12-11 02:16:52
问题 I have some text in QPlainTextEdit, where every line starts with 10 spaces: line1 line2 line3 line4 Then, I select few lines and in a loop I want to remove first two spaces from all the selected lines: cursor.beginEditBlock(); for (QTextBlock block = startBlock; block != endBlock; block = block.next()) { cursor.setPosition(block.position()); cursor.setPosition(block.position() + 2, QTextCursor::KeepAnchor); cursor.removeSelectedText(); } cursor.endEditBlock(); The problem is that the code

How to scroll QPlainTextEdit to top?

橙三吉。 提交于 2019-12-09 15:49:14
问题 I would like to automatically scroll to the top in a QPlainTextEdit widget after put in some text. How can I realize that? 回答1: myTextEdit -> moveCursor (QTextCursor::Start) ; myTextEdit -> ensureCursorVisible() ; 回答2: As QTextEdit inherits from QAbstractScrollArea , you can move its scrollbars: QScrollBar *vScrollBar = yourTextEdit->verticalScrollBar(); vScrollBar->triggerAction(QScrollBar::SliderToMinimum); 来源: https://stackoverflow.com/questions/7280965/how-to-scroll-qplaintextedit-to-top