PDA

View Full Version : QTextTable horizontal alignment of a cell



hafwil
27th May 2008, 19:11
Hello!

I would like to ask you, if you know how to horizontal align a text in a cell of a QTextTable?

Thank you,
Willi

jpn
27th May 2008, 19:13
Did you notice QTextTable::setFormat() and QTextTableFormat::setAlignment()?

hafwil
27th May 2008, 19:22
Yes, but this works only for the whole table.
I would like to have a table where the text of the first column is aligned to the left, and the second column is aligned right...

maartenS
13th October 2008, 14:35
Did you already find a solution? I'm trying this as well with no succes until now...

patrik08
13th October 2008, 20:31
http://doc.trolltech.com/main-snapshot/qtextcharformat.html#VerticalAlignment-enum


on new QTextTableCellFormat Qt 4.4. you can set padding -
setTopPadding ( qreal padding )
setRightPadding ( qreal padding )
setBottomPadding ( qreal padding )
setLeftPadding ( qreal padding )

and you can format textblock inside cell



void QTextTableCell::setFormat ( const QTextCharFormat & format )


http://doc.trolltech.com/main-snapshot/qtextcharformat.html
http://doc.trolltech.com/main-snapshot/qtexttablecellformat.html
http://doc.trolltech.com/main-snapshot/qtexttablecell.html


A fast way to generate document on qt after 4.5 is xslt!

xml data + style .. or db to xml + style xslt



#if QT_VERSION >= 0x040500
QDateTime timer1( QDateTime::currentDateTime() );
StreamBuf *buf = new StreamBuf();
QXmlQuery xquery(QXmlQuery::XSLT20);
xquery.setFocus(QUrl("http://www.qtcentre.org/forum/external.php?type=RSS2"));
xquery.bindVariable("unixtime", QVariant(timer1.toTime_t()));
xquery.bindVariable("ddate", QVariant(timer1.toString()));
xquery.bindVariable("ddformat", QVariant(QDir::homePath () ));
xquery.setQuery(QUrl("http://fop-miniscribus.googlecode.com/svn/trunk/doc/draw_paper/browser_rss.xsl"));
xquery.evaluateTo(buf->device());
_doc->setHtml ( buf->data() );
////////////buf->PutOnFile( "ddebughtml.html" );
#endif




try to build -> http://fop-miniscribus.googlecode.com/svn/trunk/doc/draw_paper/

maartenS
14th October 2008, 15:26
Thanks for your reply.

for me


QTextBlockFormat rightAlignment;
rightAlignment.setAlignment(Qt::AlignRight);

QTextTable * testTable = cursor.insertTable(4,4);
testTable->cellAt(0,0).firstCursorPosition().setBlockFormat(r ightAlignment);
testTable->cellAt(0,0).lastCursorPosition().insertText("test");
// etc.

did the trick. Previously I was unsuccesfully trying to do an insertBlock() at the cursorposition, resultiing in two textblocks per cell.