ixM
26th May 2009, 19:13
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
QTextDocument * TextDocument = new QTextDocument;
TextDocument->setTextWidth(200.0);
TextDocument->setPageSize(QSize(200, 200));
QSqlQuery Query = GetSql()->Query();
QString QueryString;
QueryString += "SELECT books.book_author, books.book_title, books.book_price ";
QueryString += "FROM catalog_book_list ";
QueryString += "LEFT JOIN books ON books.book_id = catalog_book_list.book_id ";
QueryString += "WHERE catalog_book_list.catalog_id = 1 ";
QueryString += "ORDER BY catalog_book_list.cat_book_id ASC";
Query.exec(QueryString);
QTextCursor TextCursor(TextDocument->rootFrame());
QTextList * TextList = TextCursor.insertList(QTextListFormat::ListDecimal );
QTextBlock TextBlock = TextList->item(0);
TextCursor = QTextCursor(TextBlock);
QTextCharFormat Default;
Default.setProperty(QTextFormat::CssFloat, "right");
QTextCharFormat Author;
Author.setFontWeight(QFont::Bold);
QTextCharFormat Title;
Title.setFontUnderline(true);
QTextBlockFormat BlockFormat = TextBlock.blockFormat();
QTextOption TextOption = TextDocument->defaultTextOption();
TextOption.setFlags(QTextOption::ShowLineAndParagr aphSeparators | QTextOption::ShowTabsAndSpaces);
TextOption.setWrapMode(QTextOption::WrapAtWordBoun daryOrAnywhere);
QList<QTextOption::Tab> List;
QTextOption::Tab Tab = QTextOption::Tab();
Tab.type = QTextOption::DelimiterTab;
Tab.delimiter = QChar::ParagraphSeparator;
List.append(Tab);
TextDocument->setDefaultTextOption(TextOption);
while(Query.next()) {
TextCursor.setBlockFormat(BlockFormat);
QTextFrame * mainFrame = TextCursor.currentFrame();
TextCursor.setCharFormat(Default);
TextCursor.insertText(" ");
TextCursor.setCharFormat(Author);
TextCursor.insertText(Query.value(0).toString());
TextCursor.setCharFormat(Default);
TextCursor.insertText(" ");
TextCursor.setCharFormat(Title);
TextCursor.insertText(Query.value(1).toString());
TextCursor.setCharFormat(Default);
TextCursor.insertText("\t");
TextCursor.insertText(Query.value(2).toString() +" "+ QString(QChar(8364)));
TextCursor.setCharFormat(Default);
TextCursor = mainFrame->lastCursorPosition();
if(Query.at() != Query.size() - 1)
TextCursor.insertBlock();
}
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
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
QTextDocument * TextDocument = new QTextDocument;
TextDocument->setTextWidth(200.0);
TextDocument->setPageSize(QSize(200, 200));
QSqlQuery Query = GetSql()->Query();
QString QueryString;
QueryString += "SELECT books.book_author, books.book_title, books.book_price ";
QueryString += "FROM catalog_book_list ";
QueryString += "LEFT JOIN books ON books.book_id = catalog_book_list.book_id ";
QueryString += "WHERE catalog_book_list.catalog_id = 1 ";
QueryString += "ORDER BY catalog_book_list.cat_book_id ASC";
Query.exec(QueryString);
QTextCursor TextCursor(TextDocument->rootFrame());
QTextList * TextList = TextCursor.insertList(QTextListFormat::ListDecimal );
QTextBlock TextBlock = TextList->item(0);
TextCursor = QTextCursor(TextBlock);
QTextCharFormat Default;
Default.setProperty(QTextFormat::CssFloat, "right");
QTextCharFormat Author;
Author.setFontWeight(QFont::Bold);
QTextCharFormat Title;
Title.setFontUnderline(true);
QTextBlockFormat BlockFormat = TextBlock.blockFormat();
QTextOption TextOption = TextDocument->defaultTextOption();
TextOption.setFlags(QTextOption::ShowLineAndParagr aphSeparators | QTextOption::ShowTabsAndSpaces);
TextOption.setWrapMode(QTextOption::WrapAtWordBoun daryOrAnywhere);
QList<QTextOption::Tab> List;
QTextOption::Tab Tab = QTextOption::Tab();
Tab.type = QTextOption::DelimiterTab;
Tab.delimiter = QChar::ParagraphSeparator;
List.append(Tab);
TextDocument->setDefaultTextOption(TextOption);
while(Query.next()) {
TextCursor.setBlockFormat(BlockFormat);
QTextFrame * mainFrame = TextCursor.currentFrame();
TextCursor.setCharFormat(Default);
TextCursor.insertText(" ");
TextCursor.setCharFormat(Author);
TextCursor.insertText(Query.value(0).toString());
TextCursor.setCharFormat(Default);
TextCursor.insertText(" ");
TextCursor.setCharFormat(Title);
TextCursor.insertText(Query.value(1).toString());
TextCursor.setCharFormat(Default);
TextCursor.insertText("\t");
TextCursor.insertText(Query.value(2).toString() +" "+ QString(QChar(8364)));
TextCursor.setCharFormat(Default);
TextCursor = mainFrame->lastCursorPosition();
if(Query.at() != Query.size() - 1)
TextCursor.insertBlock();
}
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