Change tab stop size in rendered HTML using Qt's QLabel class?

According to W3 (HTML4): The horizontal tab character (decimal 9 in ISO10646 and ISO88591) is usually interpreted by visual user agents as the smallest non-zero number of spaces necessary to line characters up along tab stops that are every 8 characters. We strongly discourage using horizontal tabs in preformatted text since it is common practice, when editing, to set the tab-spacing to other values, leading to misaligned documents. It's implementation-defined, essencially.

Most, if not all, browsers/renderers use eight spaces for tabs. This cannot be configured in Qt. It is, however somewhat trivial to go through your HTML and replace tabs with however many spaces you wish.

Write a simple parser for that. Pseudocode: for each block { for each line in block { position_in_line = 0 for each character in line { if character is a tab { remove tab character do { add a space character ++position_in_line } while position_in_line % 8! = 0 } else { ++position_in_line } } } } In case you're curious, HTML3 specifies the use of eight-character tabs: Within , the tab should be interpreted to shift the horizontal column position to the next position which is a multiple of 8 on the same line; that is, col := (col+8) mod 8.

Yes, I realize that I could edit the source and replace tab characters with space characters, but I explicitly mentioned in the question that I really don't want to start editing the source HTML. Besides, your parser pseudocode could be written a lot easier in python: code. Replace('\t', ' ') – Thomi Feb 14 '09 at 9:29.

While QLabel uses a QTextDocument internally when rendering rich text, it does not allow access to it in it's API. However, since QTextDocument is a QObject, you can try to use QTextDocument * tl = label->findChild(); to get access to it (will work if the QLabel creates the QTextDocument as a (direct or indirect) child of itself). Once you have a pointer to the text document, you can use the QTextDocument API, e.g. QTextOption::setTabsStop(), to change the tab stops.

The last step is to somehow make the QLabel repaint itself. Probably a call to QWidget::update() suffices, but caching (or worse, recreating the text document) might thward that.In this case, you can register an event listener on the label to adjust the text document just prior to a paintEvent(), but note that the sizent() might also change when the tab stops change, so it might be more complicated still. That said, it's how I'd approach the problem.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions