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. QToolTip with different fonts
Forum Updated to NodeBB v4.3 + New Features

QToolTip with different fonts

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.3k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    Infestor
    wrote on last edited by
    #1

    Hi,

    So i was wondering if it is possible to have the text of a QToolTip have multiple fonts. E.g the first line is bold and the second line is italic and so on.
    My assumption is that i have to call QToolTip::showText multiple times and set the font between the calls. However for this i have to change the position of the tooltip after each call and for that i would have to know the height of the tooltip box which i dont think is accessible. So how would i solve this?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use rich text in your string see here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • I Offline
        I Offline
        Infestor
        wrote on last edited by
        #3

        Yes i already tried that but i am quite confused as to how this can be used. When using a QTextEdit (this is what the rich text link leads to) i still can only return a QString which is necessary due to the ToolTip function and that QString is n ot using different fonts. Maybe i am using the QTextEdit wrong too, im not sure.

            QFont f("Arial", 15, QFont::Bold);
            QFont g("Arial", 10, QFont::Bold);
            QTextEdit t;
            t.setFont(f);
            t.append("foo\n");
            t.setFont(g);
            t.append("bar");
        
            QToolTip::showText(somePos, t.toPlainText());
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          As its name suggests toPlainText returns that: plain text, no formatting. You should get better result with toHtml.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • I Offline
            I Offline
            Infestor
            wrote on last edited by
            #5

            Of course. Thank you, that worked.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You're welcome !

              Since you have it working now, please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem corrected so that other forum users may know a solution has been found :-)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

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