A Qt widget based on QTextEdit, that changes its height automatically to accommodate the text
Project description
AutoResizingTextEdit is a simple Qt widget based on QTextEdit. Its purpose is to automatically adjust editor height to match the text, with the help of a layout it’s placed in.
It works with both Python 2 and Python 3 as well as PyQt 4 and PyQt 5 [2]
Status
The project has not undergone extensive testing on multiple platorms yet and should be considered alpha-quality. It’s already feature-complete though and, due to its simplicity and emphasis on working with Qt widget system rather than subverting it, should be safe for general use.
The code has only been tested on Arch Linux so far.
Installation
setup.py
The repository contains standard setup.py script (using setuptools). To install run:
python setup.py install --root=/your/python/site-packages/path --optimize=1
For a complete command reference see setuptools documentation.
PyPI
If you’re using pip you can install the package from PyPI repository: auto-resizing-text-edit on PyPI
pip install auto-resizing-text-edit
You can install the PyQt 4 versions that way as well:
pip install git+https://github.com/cameel/auto-resizing-text-edit.git@pyqt4-v0.1.0
AUR
If you’re using Arch Linux you can get a PKGBUILD from AUR: python-auto-resizing-text-edit in AUR
Dependencies
Usage
It’s as simple as:
from auto_resizing_text_edit import AutoResizingTextEdit
editor = AutoResizingTextEdit()
The widget also provides a simple way to constrain its minimum width to a specific number of lines (provided that all the text in the editor uses the same font; if not, you’re on your own here):
editor.setMinimumLines(3)
That’s all there is to it. You put it in a layout and forget about it:
from PyQt5.QtWidgets import QWidget, QVBoxLayout
widget = QWidget()
editor.setParent(widget)
layout = QVBoxLayout(widget)
layout.addWidget(editor)
layout.addStretch()
widget.setLayout(layout)
If you need more or just want to see the editor in action, there are a few simple but complete examples in examples/ directory.
License
Copyright © Kamil Śliwak
Released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file auto-resizing-text-edit-0.1.0.tar.gz
.
File metadata
- Download URL: auto-resizing-text-edit-0.1.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 283d912b989d86160f047b7e987f3e2153f9f04e3f6f6e653456509df74d7507 |
|
MD5 | 7df271daee9553af8cdc5ac3b377b3d2 |
|
BLAKE2b-256 | e537a1ba3535c212e9badc697f222c87e9878004c3dfdf6b4d11e1f1b70c0f27 |