spiceqert.blogg.se

Qt plain text editor
Qt plain text editor





qt plain text editor

Print_action = QAction(QIcon(os.path.join('images', 'printer.png')), "Print.", self) Saveas_file_(self.file_saveas)įile_toolbar.addAction(saveas_file_action) Saveas_file_tStatusTip("Save current page to specified file") Saveas_file_action = QAction(QIcon(os.path.join('images', 'disk-pencil.png')), "Save As.", self) Save_file_tStatusTip("Save current page") Save_file_action = QAction(QIcon(os.path.join('images', 'disk.png')), "Save", self) Open_file_action = QAction(QIcon(os.path.join('images', 'blue-folder-open-document.png')), "Open file.", self) You can use these to enable and disable buttons when they can't be used.įile_menu = nuBar().addMenu("&File")

#QT PLAIN TEXT EDITOR UPDATE#

There are also a set of signals available, such as `.copyAvailable` to update the UI when these operations are possible. The complete list of slots available on a QPlainTextEdit are - Slot Select_action = QAction(QIcon(os.path.join('images', 'selection-input.png')), "Select all", self) Paste_action = QAction(QIcon(os.path.join('images', 'clipboard-paste-document-text.png')), "Paste", self) Python cut_action = QAction(QIcon(os.path.join('images', 'scissors.png')), "Cut", self)Ĭut_tStatusTip("Cut selected text")Ĭut_()Ĭopy_action = QAction(QIcon(os.path.join('images', 'document-copy.png')), "Copy", self)Ĭopy_tStatusTip("Copy selected text")Ĭopy_() triggered signal from the QAction to the relevant slot enables the behaviour. Below we add a set of toolbar buttons for editing, each defined as a QAction. Triggering any of these operations is simply a case of calling one the slot at the appropriate time. However, the QPlainTextEdit widget actually provides support for all of this through Qt slots. Implementing all these operations on the text buffer directly would take some work. To be useful an editor needs to be able to perform a lot of standard operations - copy, paste, cut, insert, clear. # If none, we haven't got a file open yet (or creating new). # self.path holds the path of the currently open file. # Setup the QTextEdit editor configurationįixedfont = QFontDatabase.systemFont(QFontDatabase.FixedFont) Self.editor = QPlainTextEdit() # Could also use a QTextEdit and set (False) QTxtEdit.Super(MainWindow, self)._init_(*args, **kwargs) QDebug() << "Qt Version:" << QT_VERSION_STR QString::fromUtf8("HTML Meta-Characters: & \" ' and\nnon-ASCII characters: \xc3\xa4 \xc3\xb6 \xc3\xbc \xc3\x9f \xc3\x84 \xc3\x96 \xc3\x9c")Įnum Ĭonst QString formatHtml(const QString &qText, const QColor &qColor)Ĭase '': qHtmlText += QString::fromLatin1(">") break Ĭase '&': qHtmlText += QString::fromLatin1("&") break Ĭase '"': qHtmlText += QString::fromLatin1("'") break Ĭase '\'': qHtmlText += QString::fromLatin1("'") break Ĭase '\n': qHtmlText += QString::fromLatin1("") break ĭefault: qHtmlText += qChar // everything else unchanged QString::fromLatin1("Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum."), QString::fromLatin1("Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat."),

qt plain text editor

QString::fromLatin1("Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat."), QString::fromLatin1("Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."), QString::fromLatin1("Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."), QString::fromLatin1("Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."), QString::fromLatin1("Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat."), QString::fromLatin1("Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua."), it transforms "\n" to "" which may or may not be useful. To consider these, I added a simple formatter which transforms these to the resp. Īnother issue is that the plain text may contain characters which have meta-meaning in HTML, literally: & " '. This is done by surrounding the plain text with minimal HTML-markup. In the case of OP, I would recommend the latter. Text can be formatted in a limited way, either using a syntax highlighter (see below), or by appending html-formatted text with appendHtml().







Qt plain text editor