Skip to main content

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

  • Python >= 2.7

  • PyQt 5 or PyQt 4 [1] [2]

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto-resizing-text-edit-0.1.0.tar.gz (5.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page