Title attribute of html tag
-
I've checked list of all available tags/attributes but there is nothing about how to add a title into a string with html code. How to do it?
Label { textFormat: Text.RichText text: "<span title=\"TITLE\">TEXT</span>" }
-
@Cocojambo said in Title attribute of html tag:
"<span title=\"TITLE\">TEXT</span>"
Can you describe how you want to use the
title
attribute here?A
title
attribute of aspan
tag is very different from atitle
tag. The attribute is not displayed as part of the rich text. -
@JKSH Like it works for browsers - when I hover cursor above this span the title should appear. For Android app "hover" event should trigger by holding/clicking on it.
Or maybe you could advise how to achieve next functionality: user can touch (click/hover) one word from a sentence and get some tooltip (pop up help) with some text (and custom elements if it's possible). Here is an example:
-
@Cocojambo said in Title attribute of html tag:
@JKSH Like it works for browsers - when I hover cursor above this span the title should appear. For Android app "hover" event should trigger by holding/clicking on it.
I see.
The Qt rich text does not include tooltips, unfortunately.
Or maybe you could advise how to achieve next functionality: user can touch (click/hover) one word from a sentence and get some tooltip (pop up help) with some text (and custom elements if it's possible).
I can't think of an easy way of setting up tooltips for individual words/phrases. There is the QML ToolTip (https://doc.qt.io/qt-5/qml-qtquick-controls2-tooltip.html ) but you can only center it on an entire label, not on individual words.
Perhaps you can open a feature request at https://bugreports.qt.io/ and post the link here.
(Personally, I'm not sure if we should implement this as a
title
attribute... https://mrwweb.com/the-title-attribute-and-why-its-almost-useless/ ) -
Even though (as @JKSH says) QTextEdit has no tooltip support, you could try implement something similar yourself, say like:
do setAttribute(Qt::WA_Hover); on the QTextEdit window
to receive QHoverEvents for that window
get the QTextCursor for the coords of the hover
try to select a word (if any) under that QTextCursor
change the color of the selection
create a QLabel on top of and close the QTextCursor (but on the line below so not to obscure the selected text)
show what content you prefer in the QLabel
loop back to start :-) -
@JKSH Thanks, I've added a new suggestion.
@hskoglund Great advice. I also thought about WebView where I could do more "usual" for browser things but it seems too heavy for that simple task.