Results 1 to 3 of 3

Thread: How to wrap QToolTip text character-by-character instead of wrap at word-breaks ?

  1. #1
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to wrap QToolTip text character-by-character instead of wrap at word-breaks ?

    In my Linux 2.6 machine using Qt 4.7.4, default wrapping of QToolTip for long text in QTableView works fine i.e. the rich text gets wrapped at word-breaks according to min-width (although whitespaces get squeezed but that is not the bother right now).

    I want to wrap at character-level instead of word-level eg in here: http://code.google.com/p/spyderlib/s...32159e086a5af7 ,
    there is a LOC self.set_wrap_mode('character' if enable else None) [which "looks" like it wraps at character-level instead of word-level]

    To put it another way (http://qt-project.org/forums/viewthread/13368),
    QString text = "Some text: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    should be displayed in tooltip as:
    ——————⠀”———--
    | Some text: aaaa |
    | aaaaaaaaaaaaa |
    ——————⠀”——----
    whereas it is displayed as
    ——————⠀”———
    . | Some text: |
    . | aaaaaaaaaaaaaa(rest of the word is truncated because of screen resolution/size, which I want to cure!) |
    ——————⠀”——-

    Thanks

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to wrap QToolTip text character-by-character instead of wrap at word-breaks ?

    You will probably have to reimplement some of the text layout / painting code in a class you derive from QToolTip (I don't know which - you'll have to study the Qt sources for that). It makes no sense to arbitrarily break long words at random places just to make them fit on a line. It will be unreadable. It does make sense to use a hyphenation library to properly break long words and insert hyphens in correct places according to hyphenation rules.

  3. The following user says thank you to d_stranz for this useful post:

    hvc (9th April 2013)

  4. #3
    Join Date
    Apr 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to wrap QToolTip text character-by-character instead of wrap at word-breaks ?

    Yeps, agreed that we should not arbitrarily break the long word but I want to wrap the word if some characters are being obscured. I will try to intercept viewportevent and do some "trickery" (calculate size of word vis-a-vis view/display size and) eg try either of:
    • use horizontal moving tooltip (marquee tag does not seem to be available in Qtooltip or maybe I did not apply it correctly?)
    • shorten the font size while still being readable
    • use hyphenation like suggested by d_stranz or maybe QString splitting



    Will post the solution once I find/try one.

Similar Threads

  1. How to word wrap text in the rows and columns of a QTableWidget?
    By TheIndependentAquarius in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2012, 09:02
  2. QToolTip doesnt wrap text
    By superpacko in forum Qt Programming
    Replies: 0
    Last Post: 16th August 2011, 20:12
  3. word wrap
    By deeee in forum Qt Programming
    Replies: 3
    Last Post: 26th May 2010, 20:55
  4. Long text and word wrap in QPainter
    By TomASS in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2009, 12:50
  5. Word wrap of QLabel
    By jimfan in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2008, 05:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.