Hi there,

I'm having some trouble with QTextDocument, QTextCursor,...

I'm trying to generate a QTextDocument using data from a database. So far it easy but it becomes harder when I try to use tab stops (maybe it's not the right name) to achieve something like this : www.ixamaxi.be/images/problem4.png

Qt Code:
  1. QTextDocument * TextDocument = new QTextDocument;
  2. TextDocument->setTextWidth(200.0);
  3. TextDocument->setPageSize(QSize(200, 200));
  4.  
  5. QSqlQuery Query = GetSql()->Query();
  6.  
  7. QString QueryString;
  8.  
  9. QueryString += "SELECT books.book_author, books.book_title, books.book_price ";
  10. QueryString += "FROM catalog_book_list ";
  11. QueryString += "LEFT JOIN books ON books.book_id = catalog_book_list.book_id ";
  12. QueryString += "WHERE catalog_book_list.catalog_id = 1 ";
  13. QueryString += "ORDER BY catalog_book_list.cat_book_id ASC";
  14.  
  15. Query.exec(QueryString);
  16.  
  17. QTextCursor TextCursor(TextDocument->rootFrame());
  18.  
  19. QTextList * TextList = TextCursor.insertList(QTextListFormat::ListDecimal);
  20.  
  21. QTextBlock TextBlock = TextList->item(0);
  22.  
  23. TextCursor = QTextCursor(TextBlock);
  24.  
  25. QTextCharFormat Default;
  26. Default.setProperty(QTextFormat::CssFloat, "right");
  27.  
  28. Author.setFontWeight(QFont::Bold);
  29.  
  30. Title.setFontUnderline(true);
  31.  
  32. QTextBlockFormat BlockFormat = TextBlock.blockFormat();
  33.  
  34. QTextOption TextOption = TextDocument->defaultTextOption();
  35. TextOption.setFlags(QTextOption::ShowLineAndParagraphSeparators | QTextOption::ShowTabsAndSpaces);
  36.  
  37. TextOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
  38.  
  39. QList<QTextOption::Tab> List;
  40.  
  41. QTextOption::Tab Tab = QTextOption::Tab();
  42. Tab.type = QTextOption::DelimiterTab;
  43. Tab.delimiter = QChar::ParagraphSeparator;
  44. List.append(Tab);
  45.  
  46. TextDocument->setDefaultTextOption(TextOption);
  47.  
  48. while(Query.next()) {
  49. TextCursor.setBlockFormat(BlockFormat);
  50. QTextFrame * mainFrame = TextCursor.currentFrame();
  51.  
  52. TextCursor.setCharFormat(Default);
  53. TextCursor.insertText(" ");
  54.  
  55. TextCursor.setCharFormat(Author);
  56. TextCursor.insertText(Query.value(0).toString());
  57.  
  58. TextCursor.setCharFormat(Default);
  59. TextCursor.insertText(" ");
  60.  
  61. TextCursor.setCharFormat(Title);
  62. TextCursor.insertText(Query.value(1).toString());
  63.  
  64. TextCursor.setCharFormat(Default);
  65. TextCursor.insertText("\t");
  66. TextCursor.insertText(Query.value(2).toString() +" "+ QString(QChar(8364)));
  67.  
  68. TextCursor.setCharFormat(Default);
  69.  
  70. TextCursor = mainFrame->lastCursorPosition();
  71.  
  72. if(Query.at() != Query.size() - 1)
  73. TextCursor.insertBlock();
  74. }
To copy to clipboard, switch view to plain text mode 

This is the result I'm getting : http://www.ixamaxi.be/images/problem7.png

The documentation is not very "big" concerning this particular subject.

Any help would be appreciated!

Thank you very much,

Regards,

ixM