
- PyQt - Home
- PyQt - Introduction
- PyQt - Environment
- PyQt - Hello World
- PyQt - Major Classes
- PyQt - Using Qt Designer
- PyQt - Meta Objects
- PyQt Signals & Slots
- PyQt - Signals and Slots
- PyQt - Support and Signals
- PyQt - Unbound and Bound Signals
- PyQt - New Signals with PyQtSignal
- PyQt - Connecting, Disconnecting, & Emitting Signals
- PyQt - Slot decorator
- PyQt - Slot Connection
- PyQt Layouts
- PyQt - Layout Management
- PyQt - QBoxLayout
- PyQt - QGridLayout
- PyQt - QFormLayout
- PyQt - QHBoxLayout
- PyQt - QVBoxLayout
- PyQt - QStackedLayout
- PyQt - QGraphicsGridLayout
- PyQt - QGraphicsAnchorLayout
- PyQt - QGraphicsLayout
- PyQt - QGraphicsLinearLayout
- PyQt Basic Widgets
- PyQt - Basic Widgets
- PyQt - Qlabel Widget
- PyQt - QLineEdit Widget
- PyQt - QPushButton Widget
- PyQt - QRadioButton Widget
- PyQt - QCheckBox Widget
- PyQt - QComboBox Widget
- PyQt - QSpinBox Widget
- PyQt - QMessageBox
- PyQt - QDialogButtonBox Widget
- PyQt - QFontComboBox Widget
- PyQt - QDoubleSpinBox Widget
- PyQt - QToolBox Widget
- PyQt - QMenuBar, QMenu & Qaction Widgets
- PyQt - QToolTip
- PyQt - QInputDialog Widget
- PyQt - QFontDialog Widget
- PyQt - QDialog Widget
- PyQt - QFileDialog Widget
- PyQt - QTab Widget
- PyQt - QSplitter Widget
- PyQt - QDock Widget
- PyQt - QStatusBar Widget
- PyQt - QTabBar
- PyQt - QList Widget
- PyQt - QScrollBar Widget
- PyQt - QProgressBar
- PyQt - QCalendar Widget
- PyQt - QMessageBox Widget
- PyQt - QPlainTextEdit
- PyQt - QDateEdit
- PyQt - QDateTimeEdit
- PyQt - QTimeEdit
- PyQt - QTextEdit
- PyQt - QTextBrowser
- PyQt - QScrollArea
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QDialog Class
- PyQt Views
- PyQt - QColumnView
- PyQt - QTableView
- PyQt Drawing API
- PyQt - Drawing API
- PyQt - Drawing a Line
- PyQt - Drawing a Rectangle
- PyQt - Drawing a Triangle
- PyQt - Drawing a Circle
- PyQt - Drawing a Ellipse
- PyQt - Drawing a Polygon
- PyQt - Geometric Transformation
- PyQt - Drawing Effect
- PyQt Groups
- PyQt - QButtonGroup
- PyQt - QGroupBox
- PyQt Effects
- PyQt - Effects
- PyQt - Opacity Effect
- PyQt - QGraphicsBlur Effect
- PyQt - QGraphicsColorize Effect
- PyQt - QGraphicsDropShadow Effect
- PyQt Events
- PyQt - Event Handling
- PyQt - Drag & Drop Events
- PyQt - File Open Event
- PyQt - Action Event
- PyQt - Hide Event
- PyQt - Resize Event
- PyQt Database
- PyQt - Database Handling
- PyQt Essentials
- PyQt - BrushStyle Constants
- PyQt - QClipboard
- PyQt - QPixmap Class
- PyQt Useful Resources
- PyQt - Quick Guide
- PyQt - Useful Resources
- PyQt - Discussion
PyQt - QPlainTextEdit
A Plaintext refers to a group of multiple words in a readable format. We can also say unencrypted message, document, or file i.e. used as input to a cryptographic system to produce ciphertext.
Ciphertext is encrypted text transformed from plaintext.
What is QPlainTextEdit?
QPlainTextEdit, a widget in Qt, allows you to create and modify plain text in our Qt apps. Unlike QTextEdit, it's made just for plain text, making it smaller and faster for simple text tasks like writing, editing code, or showing logs. QPlainTextEdit includes features like moving the cursor, selecting text, undoing/redoing actions, and scrolling, so you can use it for many different text-based apps.
QPlainTextEdit provides a user-friendly interface and comprehensive features for developing text editors, input fields, and log viewers. Developers can customize various properties, such as placeholder text, read-only mode, and tab behavior. QPlainTextEdit allows real-time interaction via signals like textChanged() and blockCountChanged(), improving the user's text editing experience. It can be used independently or integrated into larger GUIs, making it a versatile solution for managing plain text editing tasks within Qt applications.
Signals in QPlainTextEdit
- textChanged() − This emitted when the text changes.
- blockCountChanged(int newBlockCount) − This emitted when the number of text blocks changes.
Advantages of using QPlainTextEdit
Below is the list of benefits using
- It easily works with big chunks of simple text.
- It makes building without fancy text styles easier.
- QPlainTextEdit adjust how it acts to fit what you want.
- The users undo and redo stuff they have done.
- It updates instantly when things change, like when you type.
Example 1
Following example illustrate the code snippet for plaintext in PyQt window.
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPlainTextEdit if __name__ == '__main__': app = QApplication(sys.argv) main_window = QMainWindow() # Create text entry box textedit_wid = QPlainTextEdit() # Set the background color for the text entry box textedit_wid.setStyleSheet("background-color: lightgray;") # Fill the entire available space main_window.setCentralWidget(textedit_wid) # Connect the textChanged signal to print the entered text textedit_wid.textChanged.connect( lambda: print(textedit_wid.document().toPlainText())) # Define the initial value of the text textedit_wid.document().setPlainText("Please type something here") main_window.show() # Start the event loop sys.exit(app.exec())
Output
The above code produces the following output−

Example 2
Following is another example demonstrating the code snippet for QPlainTextEdit which builds a widget container. This widget allows the user to enter the input text.
import sys from PyQt6.QtWidgets import QApplication, QMainWindow, QPlainTextEdit from PyQt6.QtCore import QSize class mainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.setMinimumSize(QSize(400, 250)) self.setWindowTitle("QPlainTextEdit") # Add text field self.b = QPlainTextEdit(self) self.b.insertPlainText("Please enter the text here.\n") self.b.move(10, 10) self.b.resize(500, 200) if __name__ == "__main__": app = QApplication(sys.argv) mainWin = mainWindow() mainWin.show() sys.exit(app.exec())
Output
The above code produces the following output−
