QTextBlockFormat.setLeftMargin (1em): How?

In the html-list with marks, when changing fontsize using format.setFontPointSize (), it crashes from the editor from the command line. I realized that the bullets stay in the same position when changing fontsize, if I set padding-left to 1em (I tried this in the html editor). How can I achieve this to write a list in Qt? Can I only set a pixel value, not an element value?

fmt=cur.charFormat() charSize=fmt.fontPointSize() if charSize==0.0: charSize=14 if direction=="up": fmt.setFontPointSize(charSize+1) if textList: blockFormat=cur.blockFormat() #blockFormat.setLeftMargin(blockFormat.leftMargin()+0.4) blockFormat.setLeftMargin(1em) cur.mergeBlockFormat(blockFormat) else: fmt.setFontPointSize(charSize-1) if textList: blockFormat=cur.blockFormat() #blockFormat.setLeftMargin(blockFormat.leftMargin()-0.4) blockFormat.setLeftMargin(1em) cur.mergeBlockFormat(blockFormat) cur.mergeCharFormat(fmt) 
+4
source share
1 answer

You can set the default indent for text lists in the QTextDocument instance that you create (I think the default is 40). Animations of this value will be used for each indentation level in the list.

 QTextDocument *doc = new QTextDocument(); doc->setIndentWidth(20); QTextCursor *cursor = new QTextCursor(doc); QTextListFormat listFormat; listFormat.setIndent(1); // First indent level, indent is 20 cursor->insertList(listFormat); // Insert items into the list listFormat.setIndent(2); // Second indent level, indent is 40 cursor->insertList(listFormat); // Insert nested list items 
0
source

Source: https://habr.com/ru/post/1500396/


All Articles