[Python] In a QTextEdit, is there an easy way to move the cursor to an anchor?

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using PyQt6 (I'm open to switching to PySide if it makes a difference).

    Is there an easy way (maybe even built-in, or close to that) to search for an anchor in the text and select it? Say for example that in the html text there's an element such as <a name="myname" href="myurl">mytext</a>. How do I make QTextEdit move the cursor to this anchor (and select the text mytext)?

    • scrollToAnchor() does not do that, it seems to be only about whether it's visible on screen.
    • find seems also not working well with HTML (or maybe I'm not using it right).

    Any ideas?

    Continue reading...

Compartilhe esta Página