Hello.I have a question, When I using the QGraphcisTextItem , I will set the document 's width to Align the text?
Do you any method to change the alignment ,but no need to using setTextWidth()?
Thank you very much!
Hello.I have a question, When I using the QGraphcisTextItem , I will set the document 's width to Align the text?
Do you any method to change the alignment ,but no need to using setTextWidth()?
Thank you very much!
QGraphicsTextItem::document() -> QTextDocument::setDefaultTextOption() and then see the various options for QTextOption.
Thank you , LyKurg
Here is my program:
void cgStaticTextElement::slot_onSetTextAlign( FParam* param )
{
int alignFlag = param->getValue<int>();
QTextOption option = document()->defaultTextOption ();
Qt::AlignmentFlag flags((Qt::AlignmentFlag)(alignFlag));
option.setAlignment ( flags );
document()->setDefaultTextOption ( option );
notifyReCache(this);
}
the option in this,have a right value ,like Qt::AlignRight , but the text in the QGraphcisTextItem 's Alignment not change.
If I have modif my program like this :
void cgStaticTextElement::slot_onSetTextAlign( FParam* param )
{
int alignFlag = param->getValue<int>();
QTextOption option = document()->defaultTextOption ();
document()->setTextWidth(200); //At here give a fixed value
Qt::AlignmentFlag flags((Qt::AlignmentFlag)(alignFlag));
option.setAlignment ( flags );
document()->setDefaultTextOption ( option );
notifyReCache(this);
}
the Alignment of the QGraphcisTextItem have changed...
I don't know why ? Would you give me a reason? Thank you .
Bookmarks