Line breaks in tooltip text



  • 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.


  • Qt Champions 2017

    Hi
    It seems to break by itself
    alt text



  • 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...


  • Qt Champions 2017

    Hmm
    i used html
    alt text

    im on win 10 too.


  • Qt Champions 2017

    @mzimmers @mrjj:

    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'>."


  • Qt Champions 2017

    @aha_1980
    Cheater ;) reading the docs.. \o/


  • Qt Champions 2017

    @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 :)



  • @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?


  • Qt Champions 2017

    Hi
    Test indicates that yes
    alt text



  • 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?


  • Qt Champions 2017

    @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 :)



  • @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)
    

  • Qt Champions 2017

    hi
    alt text

    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));
    


  • @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.