Skip to content

TextBrowser

Base classes

Name Children Inherits
TextEditMixin
prettyqt.widgets.textedit
QTextBrowser
PySide6.QtWidgets
QTextBrowser(self, /, parent: PySide6.QtWidgets.QWidget | None \= None, *, source: PySide6.QtCore.QUrl | None \= None, sourceType: PySide6.QtGui.QTextDocument.ResourceType | None \= None, searchPaths: collections.abc.Sequence[str] | None \= None, openExternalLinks: bool | None \= None, openLinks: bool | None \= None) -> None

⋔ Inheritance diagram

graph TD
  1645117378["widgets.TextBrowser"]
  1964080816["widgets.TextEditMixin"]
  1259044718["widgets.AbstractScrollAreaMixin"]
  1689631995["widgets.FrameMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  2081944844["QtWidgets.QTextBrowser"]
  2951066496["QtWidgets.QTextEdit"]
  1459025998["QtWidgets.QAbstractScrollArea"]
  3822057598["QtWidgets.QFrame"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  1964080816 --> 1645117378
  1259044718 --> 1964080816
  1689631995 --> 1259044718
  829357528 --> 1689631995
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  2751680898 --> 1689631995
  2751680898 --> 1259044718
  2751680898 --> 1964080816
  2081944844 --> 1645117378
  2951066496 --> 2081944844
  1459025998 --> 2951066496
  3822057598 --> 1459025998
  3620195106 --> 3822057598
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: TextEditMixin, QTextBrowser

Rich text browser with hypertext navigation.

Source code in prettyqt/widgets/textbrowser.py
class TextBrowser(widgets.TextEditMixin, widgets.QTextBrowser):
    """Rich text browser with hypertext navigation."""

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setOpenExternalLinks(True)

    # def dragEnterEvent(self, event):
    #     u = event.mimeData().urls()
    #     for url in u:
    #         file_path = os.path.abspath(url.toLocalFile())

    #         ext = file_path.split(".")[-1]
    #         if ext in ["txt", "md", "markdown"]:
    #             event.accept()
    #         else:
    #             event.ignore()

    # def dropEvent(self, event):
    #     event.accept()
    #     self.show_markdown_file(self.filePath)

    def set_markdown_file(self, file_path: datatypes.PathType):
        file_path = pathlib.Path(file_path)
        with file_path.open() as f:
            file_content = f.read()
        self.setMarkdown(file_content)

    def set_markdown(self, text: str):
        self.setMarkdown(text)

    def get_search_paths(self) -> list[pathlib.Path]:
        return [pathlib.Path(p) for p in self.searchPaths()]

    def set_search_paths(self, paths: Iterable[datatypes.PathType]):
        self.setSearchPaths([os.fspath(p) for p in paths])

    def get_source_type(self) -> gui.textdocument.ResourceTypeStr:
        return gui.textdocument.RESOURCE_TYPES.inverse[self.sourceType()]

:fa-brands-github: Show source on GitHub