QTextDocument has no concept of units. So values given for margins, paddings or border width have to be provided in pixels. Internally QTextDocument uses qt_defaultDpi and the QPaintDevice's dpi metrics to calculate a scale factor (see internal QTextDocumentLayout::scaleToDevice method).
So in order to apply e.g. metric values, one has to calculate a pixel value based on qt_defaultDpi (which is more or less a private function, so you must use QGuiApplication::primaryScreen()->logicalDotsPerInchX() to get that value).
But while metrics like cellPadding are correctly scaled, some values in QTextFrameFormat are not:
The attached example program tries to set the 'border' value. Attached are the results for on-screen rendering and printing.
A patch to fix this is being worked on.