Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I am trying to set tooltip display width with the following code but i am not getting the exact output?
Qt 6.12 LTS is out! See what's new in the release blog

I am trying to set tooltip display width with the following code but i am not getting the exact output?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 13.9k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #4

    i have tried this i am now getting the require width but another problem is their the tooltip text
    is not visible.
    i have used the following
    @wid.setStyleSheet("QToolTip {font-size:12pt; color:white; border 2px solid black; min-width: 10px;}");
    wid.settooltip("text");@

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #5

      [quote author="Lukas Geyer" date="1326371764"][quote author="pratik041" date="1326368889"]@ wid.setStyleSheet("QToolTip {font-size:12pt; color:white; border-width:2px; border-style:solid; width: 10px;}");@
      What is the error in the above code?[/quote]

      Well - that's the question: what is the error in the code above.

      So, what is the error in the code above? Which result do you expect? Which result do you get instead?[/quote]

      First thing is i want to set tooltip display rect to given width like if i set 40px width if the tooltip text exceeds the 40px it should display in the next line.
      Secondly the error is i am not getting the width i set and the tooltip is also not showing only the blank tooltip rect is coming.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stima_ua
        wrote on last edited by
        #6

        @QToolTip {
        font-size:12pt;
        color:white; --- Font color ----<<<< Attention!! use (pseudo code) background: ~white or color: ~white
        border 2px solid black; --- border width, style, color
        min-width: 10px;
        @

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #7

          [quote author="stima_ua" date="1326372218"]@QToolTip {
          font-size:12pt;
          color:white; --- Font color ----<<<< Attention!! use (pseudo code) background: ~white or color: ~white
          border 2px solid black; --- border width, style, color
          min-width: 10px;
          @[/quote]

          but setting pseduo code the tooltip is displaying but width portion is not working i am using "max-width" instead of "min-width".

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stima_ua
            wrote on last edited by
            #8

            @QString text = "Some text: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"@ --- its 1 line

            You want:

            .
            | Some text: aaaa |
            .
            | aaaaaaaaaaaaaa |

            You need:
            (pseudo code)

            @if ( text.size() > mySize ) {
            text.insert(mySize, "\n")
            }@

            Something like this.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #9

              [quote author="stima_ua" date="1326374757"]@QString text = "Some text: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"@ --- its 1 line

              You want:

              .
              | Some text: aaaa |
              .
              | aaaaaaaaaaaaaa |

              You need:
              (pseudo code)

              @if ( text.size() > mySize ) {
              text.insert(mySize, "\n")
              }@

              Something like this.[/quote]

              ya i want like this. Is it possible through stylesheet?
              I can do this by inserting "\n" in the tooltip string but the problem is that i want to break string according to pixels width.Do you have any way for doing this?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                stima_ua
                wrote on last edited by
                #10

                hm...i think its possible, but i dont know how((;

                p.s. If you find solution post him plz

                p.s.s. mb use QTextLayout ... sorry but i have not time to test))

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #11

                  [quote author="stima_ua" date="1326376375"]hm...i think its possible, but i dont know how((;

                  p.s. If you find solution post him plz[/quote]

                  I have tried using QfontMetrices . Here i am able to find the total text pixel size but i don't able to find how to break it according to pixels size.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    joonhwan
                    wrote on last edited by
                    #12

                    After reading this post, I checked Qt doc and found.

                    bq. Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p >.

                    Hmm.. if your text is not wrapped, what was the problem then? wierd.

                    joonhwan at gmail dot com

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #13

                      [quote author="joonhwan" date="1326405736"]After reading this post, I checked Qt doc and found.

                      bq. Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p >.

                      Hmm.. if your text is not wrapped, what was the problem then? wierd.[/quote]

                      I want to write a function where i will provide required text width in pixels and that function will set the tooltip display width to specified pixels width and the line exceeding it will be come to the next line.Can you say me what useful information you found in the doc related to this and How can i use that to achieve this with some example?

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