mihnen
11th September 2012, 05:08
I have a QGraphicsTextItem that I am autosizing the font in, I can't let the document() line break automatically because in order to do my alignment i need to setTextWidth(boundingRect.width()) which makes it break when I don't want it to.
The expected behavior should be to autosize as large as possible and then shrink until the minimum font size is hit, then I want to insert a linebreak.
The way I am currently implementing this autosizing is by using fontmetrics inside of the documents contentsChange(int,int,int) handler and it causes a recursive loop by trying to insert a "\n"
if((f.pointSizeF() * factor) < m_minFontSize) {
f.setPointSizeF(m_minFontSize);
text.append("\n");
disconnect(this->document(), SIGNAL(contentsChange(int,int,int)),
this, SLOT(contentsChangedHandler(int,int,int)));
this->setPlainText(text);
connect(this->document(), SIGNAL(contentsChange(int,int,int)),
this, SLOT(contentsChangedHandler(int,int,int)));
}
I have tried both blockSignals(true) blockSignals(false) wrapper and a disconnect and connnect wrapper and neither one stops the recursion. What is the normal way to implement manual line wrapping in a textdocument?
The expected behavior should be to autosize as large as possible and then shrink until the minimum font size is hit, then I want to insert a linebreak.
The way I am currently implementing this autosizing is by using fontmetrics inside of the documents contentsChange(int,int,int) handler and it causes a recursive loop by trying to insert a "\n"
if((f.pointSizeF() * factor) < m_minFontSize) {
f.setPointSizeF(m_minFontSize);
text.append("\n");
disconnect(this->document(), SIGNAL(contentsChange(int,int,int)),
this, SLOT(contentsChangedHandler(int,int,int)));
this->setPlainText(text);
connect(this->document(), SIGNAL(contentsChange(int,int,int)),
this, SLOT(contentsChangedHandler(int,int,int)));
}
I have tried both blockSignals(true) blockSignals(false) wrapper and a disconnect and connnect wrapper and neither one stops the recursion. What is the normal way to implement manual line wrapping in a textdocument?