How i can center a image on QTextDocument? / set aligment? set border?

if i use toImageFormat() from QTextBlockFormat the image is not visible... why?

can i subclass QTextImageFormat and paint differents..? is this possibel?



Qt Code:
  1. /* http://www.zvon.org/xxl/xslfoReference/Output/index.html */
  2. bool FopFormat::ImageParserTag( const QDomElement &e )
  3. {
  4. QPixmap pixm;
  5. qreal wi = ConvertUnit( e.attribute( "width" ));
  6. qreal hi = ConvertUnit( e.attribute( "height" ));
  7. bool having = false;
  8.  
  9. /* search special alignment on fo:external-graphic */
  10. QDomNamedNodeMap attlist = e.attributes();
  11. for (int i=0; i<attlist.count(); i++){
  12. QDomNode nod = attlist.item(i);
  13. if (nod.nodeName().toLower() == "text-align") {
  14. if (nod.nodeValue().toLower() == "center" ) {
  15. pf.setAlignment( Qt::AlignCenter );
  16. } else if (nod.nodeValue().toLower() == "left" || nod.nodeValue().toLower() == "start" || nod.nodeValue().toLower() == "inside" ) {
  17. pf.setAlignment( Qt::AlignLeft );
  18. } else if (nod.nodeValue().toLower() == "right" || nod.nodeValue().toLower() == "end" ) {
  19. pf.setAlignment( Qt::AlignRight );
  20. } else if (nod.nodeValue().toLower() == "justify") {
  21. pf.setAlignment( Qt::AlignJustify );
  22. } else if (nod.nodeValue().toLower() == "inherit") {
  23. /* align same as parent before */
  24. pf.setAlignment( Qt::AlignAbsolute );
  25. }
  26. }
  27. }
  28.  
  29. QTextImageFormat format; /////////// = pf.toImageFormat(); /* destroy imageformat */
  30.  
  31. const QString href = e.attribute( "src" );
  32. if (!href.endsWith( ".svg" )) {
  33. QFile file(href);
  34. if (file.exists()) {
  35. pixm.load(href);
  36. QFileInfo fi(href);
  37. Tdoc->addResource( QTextDocument::ImageResource, QUrl(href), QPixmap(QString(":%1").arg(fi.baseName())) );
  38. having = true;
  39. }
  40. }
  41. if (having) {
  42. format.setAnchor(true);
  43. format.setAnchorHref ( href );
  44. if (wi > 0) {
  45. format.setWidth( wi );
  46. } else {
  47. format.setWidth( pixm.width() );
  48. }
  49. if (hi > 0) {
  50. format.setHeight( hi );
  51. } else {
  52. format.setHeight( pixm.height() );
  53. }
  54. format.setName( href );
  55. format.setToolTip(QString("Image %1 %2x%3").arg(href).arg(wi).arg(hi));
  56. Tcursor->insertImage( format );
  57. }
  58. return having;
  59. }
To copy to clipboard, switch view to plain text mode