PDA

View Full Version : How to wrap QToolTip text character-by-character instead of wrap at word-breaks ?



hvc
5th April 2013, 13:15
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/source/browse/spyderlib/widgets/shell.py?r=b4da90f3e5dc838f1e8e1ceacb32159e086a5af 7 ,
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

d_stranz
6th April 2013, 18:54
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 (http://swolter.sdf1.org/software/libhyphenate.html) to properly break long words and insert hyphens in correct places according to hyphenation rules.

hvc
9th April 2013, 07:26
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.