Skip to main content

A Python library providing modern Markdown and LaTeX widgets for PyQt/PySide.

Project description

QMarkdownWidget

PyPI version License: MIT

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 on QLabel for 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 on QWebEngineView for 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: If True, the widget shrinks to fit its content. If False, 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.

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

qmarkdownwidget-1.2.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qmarkdownwidget-1.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file qmarkdownwidget-1.2.1.tar.gz.

File metadata

  • Download URL: qmarkdownwidget-1.2.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for qmarkdownwidget-1.2.1.tar.gz
Algorithm Hash digest
SHA256 36ae1e20ed89107a5c53ea2fc82c32f8e8d707032c5d3cc983df0cf32188ca75
MD5 50015335cfafadd177cbeba2a5e5e0dd
BLAKE2b-256 59e12ea240159d8aab7e957c2297c97fefc2839ff60786c7b805ec871abcfddf

See more details on using hashes here.

File details

Details for the file qmarkdownwidget-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for qmarkdownwidget-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8b374907f857cf3a2e3281d9e14a4654ddd5ebeddbc67fd3efb32fcd03af77d2
MD5 437273ed7eeaddd701e1dbfc6c17f289
BLAKE2b-256 23a3173fe00033b5f9c591d1faba2f65b0d1fd7d1bc66cab0b03eb30c9a41b08

See more details on using hashes here.

Supported by

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