qtextedit

How to program scrollbar to jump to bottom/top in case of change in QPlainTextEdit or QTextEdit area?

◇◆丶佛笑我妖孽 提交于 2019-11-30 18:08:48
How to program scrollbar to jump to bottom/top in case of change in QPlainTextEdit or QTextEdit area? It looks like it doesn't have any controlling function. QTextEdit and QPlainTextEdit are both inherited from QAbstractScrollArea. The QAbstractScrollArea object provides access to the scrollbar through the verticalScrollBar() method. Thus, to jump to the top: ui.textEdit->verticalScrollBar()->setValue(0); And to jump to the bottom: ui.textEdit->verticalScrollBar()->setValue(ui.textEdit->verticalScrollBar()->maximum()); This should work for both QTextEdit and QPlainTextEdit. You can use the

How to dynamically update QTextEdit

老子叫甜甜 提交于 2019-11-30 10:30:58
so I have a QTextEdit within a Main Window in my GUI. I want to live update the text in this by pulling from a remotely updating list. I don't know how to infinitely check this list, without either a) doing an infinite loop or b) thread. a) Crashes the GUI, as it is an infinite loop b) produces an error saying: QObject: Cannot create children for a parent that is in a different thread. Which I understand. What could I do to fix this? this is how it works without threads :) 1) Create pyqt textEditor logView: self.logView = QtGui.QTextEdit() 2)add pyqt texteditor to layout: layout = QtGui

QTextEdit. How to select text manually?

℡╲_俬逩灬. 提交于 2019-11-30 02:19:45
问题 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? 回答1: 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

PyQt5 QTextEdit auto completion

孤街醉人 提交于 2019-11-29 23:03:09
问题 Looking for a way to have an auto completion with a QTextEdit and QCompleter. I have read that it is possible but didn't find any example... I'm using python3.4 and PyQt5 I'm looking for a very basic example thanks for any help 回答1: an example here...that i've worked on... although it is in python3.3 and pyqt4. I guess it should not make much of a difference.. you will have to change from PyQt4 to from PyQt5 shortcut keys are Ctrl+Space to show suggestions and Ctrl+E to autocomplete the first

How to dynamically update QTextEdit

心不动则不痛 提交于 2019-11-29 15:46:32
问题 so I have a QTextEdit within a Main Window in my GUI. I want to live update the text in this by pulling from a remotely updating list. I don't know how to infinitely check this list, without either a) doing an infinite loop or b) thread. a) Crashes the GUI, as it is an infinite loop b) produces an error saying: QObject: Cannot create children for a parent that is in a different thread. Which I understand. What could I do to fix this? 回答1: this is how it works without threads :) 1) Create pyqt

How to serialize and deserialize rich text in QTextEdit?

大城市里の小女人 提交于 2019-11-29 15:45:35
Say I have a structure like this: class AAA { BBB bb_member; double dbl_member; .................... } class BBB { int int_member; QString QStr_member; ................. QTextEdit m_textEdit; } And for AAA I define this operators: QDataStream &operator<<(QDataStream &out, const AAA &aa) { out << aa.bb_member << aa.dbl_member; return out; } QDataStream &operator>>(QDataStream &in, AAA &aa) { BBB bb_memb; double dbk_memb; in >> bb_memb >> dbk_memb; aa = AAA(bb_memb, dbk_memb); return in; } Then I call this: QFile file("myFileName"); file.open(QIODevice::WriteOnly)) QDataStream out(&file); out <<

A QWidget like QTextEdit that wraps its height automatically to its contents?

ぃ、小莉子 提交于 2019-11-29 04:30:50
I am creating a form with some QTextEdit widgets. The default height of the QTextEdit exceeds a single line of text and as the contents' height exceeds the QTextEdit's height, it creates a scroll-bar to scroll the content. I would like to override this behaviour to create a QTextEdit that would rather wrap its height to its contents. This means that the default height would be one line and that on wrapping or entering a new line, the QTextEdit would increase its height automatically. Whenever the contents height exceeds the QTextEdit's height, the latter should not create a scroll bar but

Several ways of placing an image in a QTextEdit

梦想的初衷 提交于 2019-11-28 16:44:37
I think this is a very simple question, but when I copy an image I can't paste it in a QTextEdit? Paste is inactive! Also I would like to know how to drag-and-drop a picture. BTW I use the following code in order to insert a picture into a QTextEdit: QTextEdit *textEditor = new QTextEdit(0); QTextDocumentFragment fragment; fragment = QTextDocumentFragment::fromHtml("<img src='C:\\aaa.jpg'>"); textEditor->textCursor().insertFragment(fragment); textEditor->setVisible(true); Is it recommended? How do you do this operation? Narek The second way is this: void TextEdit::insertImage() { QString file

Get text from qtextedit and assign it to a variable

岁酱吖の 提交于 2019-11-28 14:27:56
When I try to get the text from the qtextedit created with PyQt5 Designer I get an error or "Python stop working" and the script stop automatically. I've tried multiple solutions but nothing works. I have to assign the text from the qtextedit to a variable, for check if the process run or no. That's the code generated by PyQt5: from PyQt5 import QtCore, QtGui, QtWidgets import psutil class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(221, 157) MainWindow.setMinimumSize(QtCore.QSize(221, 157)) MainWindow.setMaximumSize(QtCore

Center the Text of QTextEdit horizontally and vertically

空扰寡人 提交于 2019-11-28 12:53:56
I want to center the text of my QTextEdit horizontally and vertically. I tried this, but it didn't work. m_myTextEdit = new QTextEdit("text edit", m_ui->centralWidget); m_myTextEdit->setGeometry(5, 50, 400, 250); m_myTextEdit->setReadOnly(true); m_myTextEdit->setAlignment(Qt::AlignCenter); Is there a opportunity to set it centered with a StyleSheet? If you only need one line, you can use a QLineEdit instead: QLineEdit* lineEdit = new QLineEdit("centered text"); lineEdit->setAlignment(Qt::AlignCenter); If you only want to display the text, not allow the user to edit it, you can use a QLabel