Is there a way to make links clickable in a QTextEdit
?
I know I can use a QTextBrowser
and connect to anchorClicked
but I'd rather keep the editing and viewing all in one widget, and have clickable links when I set the widget to read-only mode.
Is this possible or am I stuck with having two separate widgets in a stack and switching between them?
Enter the full address (including https) or file location you want the link to navigate to in the field, and press Enter. Now you have a link clickable in text.
If you find the HTML support insufficient for your needs you may consider the use of Qt WebKit, which provides a full-featured web browser widget. The shape of the mouse cursor on a QTextEdit is Qt::IBeamCursor by default.
Highlight the text you want to link. Click on the Add Link icon in the text editing bar (or Ctrl+K). Paste or type the URL you want to link to in the field and click “OK.” Now you have your hyperlink.
Setting this property makes the editor display a grayed-out placeholder text as long as the document () is empty. By default, this property contains an empty string. This property was introduced in Qt 5.2. See also document (). This property holds the text editor's contents as plain text.
Since QTextBrowser
inherits from QTextEdit
, you should use it and set the readOnly
property to false. Then you can change the style of the QTextBrowser as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With