Search code examples
c++qtqt4qtexteditqtextdocument

Horizontal line in QTextEdit


I'm trying to put an horizontal line in a QTextDocument. I'm using HTML for the formatting. To draw the line I want, I naturally used the <hr /> tag. But the line is drawn gray and and I'd like to change its color to black.

The styles doesn't seem to apply on the hr element, so is there a simple workaround to have horizontal black line in my document?

Thanks.


Solution

  • Coming from HTML, <hr> does not really have the ability to be colored or formatted. IE did it with color, Mozilla with background-color etc. So the best (both in HTML/css and QTextDocument) is to avoid <hr> and take instead any very small element, size it appropriately and give it a border and a background-color of same color as the border. E.g. a table row. I can dig up some code tomorrow or the day after - I have done this before so it must be somewhere.