Line breaks in tooltip text
-
wrote on 16 Oct 2017, 15:42 last edited by A Former User
I'm adding some tooltips to an app. Do I need to manually embed line breaks for a more pleasing appearance, or is there something Qt can do for me?
Thanks.
-
-
wrote on 16 Oct 2017, 16:02 last edited by
Hmm...it doesn't on mine. I can't get a screen capture of the tooltip, but it's one line and is wider than my main widget. I'm running on Windows 10; not sure whether that is the difference...
-
-
Stating the help: http://doc.qt.io/qt-5.9/qtooltip.html
"Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p style='white-space:pre'>."
-
Stating the help: http://doc.qt.io/qt-5.9/qtooltip.html
"Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p style='white-space:pre'>."
@aha_1980
Cheater ;) reading the docs.. \o/ -
@mrjj said in Line breaks in tooltip text:
@aha_1980
Cheater ;) reading the docs.. \o/He! Sometimes they are wrong and that makes it even harder :)
-
@mrjj said in Line breaks in tooltip text:
@aha_1980
Cheater ;) reading the docs.. \o/He! Sometimes they are wrong and that makes it even harder :)
wrote on 16 Oct 2017, 16:14 last edited by@aha_1980 I just used the settooltip() function:
ui->plainTextEdit->setToolTip("This area contains messages received from the target device. " \ "Currently target debug information is not displayed.");
So is this not wrapping because it's not rich text?
-
-
wrote on 16 Oct 2017, 16:41 last edited by
I'm still trying to do this programmatically, but so far without success. Here's my code:
QString richText = "This area contains messages received from the target device. "\ "Currently target debug information is not displayed."; QLabel l_toolTip; l_toolTip.setText(richText); l_toolTip.setTextFormat(Qt::RichText); ui->plainTextEdit->setToolTip(l_toolTip.text());
What am I doing wrong here?
-
I'm still trying to do this programmatically, but so far without success. Here's my code:
QString richText = "This area contains messages received from the target device. "\ "Currently target debug information is not displayed."; QLabel l_toolTip; l_toolTip.setText(richText); l_toolTip.setTextFormat(Qt::RichText); ui->plainTextEdit->setToolTip(l_toolTip.text());
What am I doing wrong here?
@mzimmers
That the text is not rich text.
still just plain text.To cheat you can use Designer and then grab the code from
setupUI()hmm. Odd using your text, it still dont word break :) -
@mzimmers
That the text is not rich text.
still just plain text.To cheat you can use Designer and then grab the code from
setupUI()hmm. Odd using your text, it still dont word break :)wrote on 16 Oct 2017, 17:12 last edited by@mrjj it is rich text according to the debugger:
QString richText = "This area contains messages received from the target device. "\ "Currently target debug information is not displayed."; QLabel l_toolTip; l_toolTip.setText(richText); enum Qt::TextFormat i = l_toolTip.textFormat(); qDebug() << i; l_toolTip.setTextFormat(Qt::RichText); i = l_toolTip.textFormat(); qDebug() << i; ui->plainTextEdit->setToolTip(l_toolTip.text());
I get this:
Qt::TextFormat(AutoText) Qt::TextFormat(RichText)
-
Rich text looks like this
<html><head/><body><p>this area contains messages received from the target device. Currently target debug information is not displayed</p></body></html>
I dont think you can just lie to it about the format.
Code from Designer
pushButton->setToolTip(QApplication::translate("MainWindow", "<html><head/><body><p>this area contains messages received from the target device. Currently target debug information is not displayed</p></body></html>", Q_NULLPTR));
-
hi
Rich text looks like this
<html><head/><body><p>this area contains messages received from the target device. Currently target debug information is not displayed</p></body></html>
I dont think you can just lie to it about the format.
Code from Designer
pushButton->setToolTip(QApplication::translate("MainWindow", "<html><head/><body><p>this area contains messages received from the target device. Currently target debug information is not displayed</p></body></html>", Q_NULLPTR));
wrote on 16 Oct 2017, 17:34 last edited by@mrjj yeah, you're right...I just discovered that. Somewhat misleading documentation, IMO, but maybe it's just me.
Anyway, this works:
char myToolTip[] = "<html><head/><body><p>This area contains messages " \ "received from the target device. " \ "Currently target debug information is not displayed." \ "</p></body></html>"; ui->plainTextEdit->setToolTip(myToolTip);
Thanks to all for the assistance.
2/14