Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Line breaks in tooltip text

Line breaks in tooltip text

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 11.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mzimmers
    wrote on 16 Oct 2017, 15:42 last edited by A Former User
    #1

    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.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 16 Oct 2017, 15:58 last edited by
      #2

      Hi
      It seems to break by itself
      alt text

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mzimmers
        wrote on 16 Oct 2017, 16:02 last edited by
        #3

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 Oct 2017, 16:04 last edited by mrjj
          #4

          Hmm
          i used html
          alt text

          im on win 10 too.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 16 Oct 2017, 16:06 last edited by
            #5

            @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 has to stay free or it will die.

            M 1 Reply Last reply 16 Oct 2017, 16:08
            1
            • A aha_1980
              16 Oct 2017, 16:06

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

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 16 Oct 2017, 16:08 last edited by
              #6

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

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 16 Oct 2017, 16:09 last edited by
                #7

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

                Qt has to stay free or it will die.

                M 1 Reply Last reply 16 Oct 2017, 16:14
                0
                • A aha_1980
                  16 Oct 2017, 16:09

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

                  M Offline
                  M Offline
                  mzimmers
                  wrote on 16 Oct 2017, 16:14 last edited by
                  #8

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

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 16 Oct 2017, 16:16 last edited by
                    #9

                    Hi
                    Test indicates that yes
                    alt text

                    1 Reply Last reply
                    2
                    • M Offline
                      M Offline
                      mzimmers
                      wrote on 16 Oct 2017, 16:41 last edited by
                      #10

                      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?

                      M 1 Reply Last reply 16 Oct 2017, 16:48
                      0
                      • M mzimmers
                        16 Oct 2017, 16:41

                        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?

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 16 Oct 2017, 16:48 last edited by mrjj
                        #11

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

                        M 1 Reply Last reply 16 Oct 2017, 17:12
                        0
                        • M mrjj
                          16 Oct 2017, 16:48

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

                          M Offline
                          M Offline
                          mzimmers
                          wrote on 16 Oct 2017, 17:12 last edited by
                          #12

                          @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)
                          
                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 16 Oct 2017, 17:25 last edited by mrjj
                            #13

                            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));
                            
                            M 1 Reply Last reply 16 Oct 2017, 17:34
                            3
                            • M mrjj
                              16 Oct 2017, 17:25

                              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));
                              
                              M Offline
                              M Offline
                              mzimmers
                              wrote on 16 Oct 2017, 17:34 last edited by
                              #14

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

                              1 Reply Last reply
                              1

                              2/14

                              16 Oct 2017, 15:58

                              topic:navigator.unread, 12
                              • Login

                              • Login or register to search.
                              2 out of 14
                              • First post
                                2/14
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved