QMarkdownWidget
QMarkdownWidget is a Python library that provides modern and feature-rich widgets for rendering Markdown and LaTeX in PyQt and PySide applications. It offers two distinct components tailored for different use cases.
Features
QMLabel: A lightweight and efficient widget based onQLabelfor rendering simple Markdown. It's fast and ideal for displaying basic formatted text without the overhead of a full web engine.QMView: A powerful widget based onQWebEngineViewfor displaying complex Markdown documents.- They offer:
- Full GFM (GitHub-Flavored Markdown) support.
- High-quality LaTeX rendering via MathJax(only QMView supports).
- Advanced auto-sizing to precisely fit its content.
- Full styling capabilities using both QSS and internal CSS.
Installation
You can install QMarkdownWidget from PyPI:
pip install QMarkdownWidget
Usage
Here are some examples of how to use the widgets.
Basic QMLabel Usage
QMLabel is as simple to use as a standard QLabel.
import sys
from qtpy.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget
from QMarkdownWidget import QMLabel
app = QApplication(sys.argv)
window = QMainWindow()
central_widget = QWidget()
layout = QVBoxLayout(central_widget)
label_text = """
# This is a QMLabel
- Renders **basic** Markdown.
- Very *lightweight*.
"""
label = QMLabel(label_text)
layout.addWidget(label)
window.setCentralWidget(central_widget)
window.show()
sys.exit(app.exec())
Basic QMView Usage
QMView can handle much more complex content, including LaTeX and code blocks.
import sys
from qtpy.QtWidgets import QApplication, QMainWindow
from QMarkdownWidget import QMView
app = QApplication(sys.argv)
window = QMainWindow()
view_text = r"""
# This is a QMView
It supports **Markdown** and LaTeX, like $E=mc^2$
"""
view = QMView(view_text)
window.setCentralWidget(view)
window.show()
sys.exit(app.exec())
Advanced: QMView Auto-Sizing
The setAutoSize method gives you powerful control over the widget's layout.
import sys
from qtpy.QtWidgets import QApplication, QMainWindow
from QMarkdownWidget import QMView
# 1. Basic auto-sizing: shrinks to fit content
view1 = QMView("Shrinks to fit.")
view1.setAutoSize(True)
# 2. Width-constrained: content wraps at 300px, height adjusts
view2 = QMView("This long text will wrap...")
view2.setAutoSize(True, max_width=300)
# 3. Height-constrained: content is clipped at 150px with a scrollbar
view3 = QMView("This tall content will be scrollable...")
view3.setAutoSize(True, max_height=150)
...
API Reference
QMLabel
A lightweight widget for simple Markdown.
-
__init__(self, text: str = "", parent=None)- Initializes the label with optional Markdown text.
-
setMarkdown(self, text: str)- Renders and displays a new Markdown string.
QMView
A full-featured widget for complex Markdown, code, and LaTeX.
-
__init__(self, text: str = "", parent=None)- Initializes the view with optional Markdown text.
-
setMarkdown(self, text: str)- Renders and displays a new Markdown string.
-
setAutoSize(self, enabled: bool, max_width: int = -1, max_height: int = -1)- Enables or disables auto-sizing.
enabled: IfTrue, the widget shrinks to fit its content. IfFalse, it expands to fill available space.max_width: Constrains the content's width, forcing text to wrap. The widget's height will adjust accordingly.max_height: Constrains the widget's height. If content is taller, a vertical scrollbar will appear.
-
setHtmlStyle(self, style: str)- Injects a custom CSS string to style the internal HTML content. This is useful for changing fonts, colors, etc., beyond what QSS can target.
Contributing
Contributions, issues, and feature requests are welcome! Please feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.
Metadata
Release files for QMarkdownWidget 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| qmarkdownwidget-1.2.1.tar.gz | 14.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qmarkdownwidget-1.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.9 kB
Release files / qmarkdownwidget-1.2.1.tar.gz
| Download URL | qmarkdownwidget-1.2.1.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36ae1e20ed89107a5c53ea2fc82c32f8e8d707032c5d3cc983df0cf32188ca75
|
|
BLAKE2b-256 checksum How to use checksums |
59e12ea240159d8aab7e957c2297c97fefc2839ff60786c7b805ec871abcfddf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / qmarkdownwidget-1.2.1-py3-none-any.whl
| Download URL | qmarkdownwidget-1.2.1-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b374907f857cf3a2e3281d9e14a4654ddd5ebeddbc67fd3efb32fcd03af77d2
|
|
BLAKE2b-256 checksum How to use checksums |
23a3173fe00033b5f9c591d1faba2f65b0d1fd7d1bc66cab0b03eb30c9a41b08
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|