dec0ding
12th January 2006, 16:20
If I post on wrong forum, just move the post ;) couldn't find better one (no cathegory for snipplets?)
I have bad experience with QTextEdit's align Justify features. The Align methods for putting Justified align are not working, although the three other Qt:: nodes do work, like Qt::AlignCenter, Qt::AlignRight, Qt::AlignLeft. However Qt::AlignJustify doesn't, and it makes the text in QTextEdit object goes nuts. However Trolltech put warning at Qt refference about this flag:
Qt::AlignJustify - Justifies the text in the available space. Does not work for everything and may be interpreted as AlignAuto in some cases.
So here is a way for making your text in QTextEdit Object be Aligned as 'Justify':
QTextEdit *mainTextEdit=new QTextEdit(this); // the object where the text is displayed
…
connect(mainTextEdit, SIGNAL(cursorPositionChanged( int , int )), this, SLOT(toggleIfStyle(int, int)) );
…
// then in the toggleIfStyle(int,int) method we have:
void class::toggleIfStyle(int a, int b)
{
QString textParagragh(mainTextEdit->text(a)); // the text of the current paragraph
mainTextEdit->insertAt(â€<p align=justify>â€, a, 0); // QTextEdit reads HTML tags, so we enter the align=justify tag
mainTextEdit->insertAt(â€</p>â€, a, mainTextEdit->paragraphLength(a)); // close the tag
mainTextEdit->setText(mainTextEdit->text()); // the text has to be re-displayed
}
Hope sometimes, to someone will help
:)
Bye
I have bad experience with QTextEdit's align Justify features. The Align methods for putting Justified align are not working, although the three other Qt:: nodes do work, like Qt::AlignCenter, Qt::AlignRight, Qt::AlignLeft. However Qt::AlignJustify doesn't, and it makes the text in QTextEdit object goes nuts. However Trolltech put warning at Qt refference about this flag:
Qt::AlignJustify - Justifies the text in the available space. Does not work for everything and may be interpreted as AlignAuto in some cases.
So here is a way for making your text in QTextEdit Object be Aligned as 'Justify':
QTextEdit *mainTextEdit=new QTextEdit(this); // the object where the text is displayed
…
connect(mainTextEdit, SIGNAL(cursorPositionChanged( int , int )), this, SLOT(toggleIfStyle(int, int)) );
…
// then in the toggleIfStyle(int,int) method we have:
void class::toggleIfStyle(int a, int b)
{
QString textParagragh(mainTextEdit->text(a)); // the text of the current paragraph
mainTextEdit->insertAt(â€<p align=justify>â€, a, 0); // QTextEdit reads HTML tags, so we enter the align=justify tag
mainTextEdit->insertAt(â€</p>â€, a, mainTextEdit->paragraphLength(a)); // close the tag
mainTextEdit->setText(mainTextEdit->text()); // the text has to be re-displayed
}
Hope sometimes, to someone will help
:)
Bye