Python Forum

Full Version: How can I show Markdown with locally stored images?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to show markdown within a Qt app which I've got working (it's a bit average with the externally referenced markdown script link...), but I want to show images as well within it that are locally stored, and this isn't working as is.

This is my code:
from PyQt6.QtWidgets import (QMainWindow, QApplication, QVBoxLayout,
							 QWidget, QPushButton)
from PyQt6.QtWebEngineWidgets import QWebEngineView
from PyQt6.QtCore import Qt


class mainWin(QMainWindow):
	def __init__(self, parent=None):
		super(mainWin, self).__init__(parent)
		self.setupUI()

	def setupUI(self):
		self.setGeometry(0, 0, 300, 200)
		central_widget = QWidget()
		vbox = QVBoxLayout()
		vbox.setAlignment(Qt.AlignmentFlag.AlignCenter)

		central_widget.setLayout(vbox)

		markdown_html = r'''<!DOCTYPE html>
		<html>
		    <head>
		        <title></title>
		        <style>
		        	:root {
		            	font-family: "Roboto";
		            	font-size: 10pt;
		        	}
		    </style>
		        <script type="module" src="https://md-block.verou.me/md-block.js"></script>
		    </head>
		    <body>
		        <md-block>**Click** on a function's info icon to see a description and usage examples.
		![Image](help/T1/image.png)</md-block>
		    </body>
		</html>
		'''
		help_md = QWebEngineView()
		help_md.setHtml(markdown_html)

		vbox.addWidget(help_md)
		self.setCentralWidget(central_widget)

	def on_btn_clicked(self):
		print("button clicked")


if __name__ == '__main__':
	import sys

	app = QApplication(sys.argv)
	win = mainWin()
	win.setWindowTitle("Main Window")
	win.show()

	sys.exit(app.exec())
How can I show images?
Also, how would I use a local md-block reference instead of external? I've tried copying the md-block.js from that external source into a local file and using that as the source, but no worky... I'm canoeing with a broken paddle I feel.