c++qtqtextcursor

How to Style Horizontal Line using QTextCursor


I am trying to add a horizontal Line to the QTextCursor and change the thickness and color of the line using below code:

QTextDocument doc=new QTextDocument();
QTextCursor *cursor=new QTextCursor(doc);
cursor->insertHtml("<hr style='color:black;height:30px'>");

I am able to draw the horizontal line butthe color and the thickness of the line are not changed. Any help will be appreciated!


Solution

  • Below code can be used to draw a horizontal line using QTextDocument and QtextCursor:

    QTextFrameFormat frameFormat;
    frameFormat.setHeight(10);
    frameFormat.setWidth(2350);
    frameFormat.setBackground(Qt::black);
    cursor->insertFrame(frameFormat);