How to synchronize QTextEdit width with QPrinter Paper width, and QTextEdit document margin with QPrinter page margin.

I not have a good method

Width like sync with this code. But I'm not sure.
Qt Code:
  1. //sync width
  2. int mw=printer.paperSize(QPrinter::DevicePixel).width();
  3. ui->textEdit->setMaximumWidth(mw);
To copy to clipboard, switch view to plain text mode 


And code for sync margin still not work
Qt Code:
  1. //sync margin
  2. printer.setPageMargins(20, 20, 20, 20, QPrinter::DevicePixel);
  3. ui->textEdit->document()->setDocumentMargin(20);
  4.  
  5.  
  6. //I use GIMP and get 1pixel is 0.35 millimeter
  7. qreal aa=0.35 * 20.0;
  8. printer.setPageMargins(aa, aa, aa, aa, QPrinter::Millimeter);
  9. ui->textEdit->document()->setDocumentMargin(20);
To copy to clipboard, switch view to plain text mode 


Sorry, with my english..