Merge pull request #1323 from bhangart/fix/element-editor-text-field-width-anchor

Keep an element editor text field in place when its width changes
This commit is contained in:
Laurent Trinques
2026-10-06 16:23:53 +02:00
committed by GitHub
@@ -235,7 +235,10 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) {
m_uuid = QUuid(dom_elmt.attribute("uuid", QUuid::createUuid().toString()));
setFrame(dom_elmt.attribute("frame", "false") == "true"? true : false);
//The saved position is the one to keep
m_block_alignment = true;
setTextWidth(dom_elmt.attribute("text_width", QString::number(-1)).toDouble());
m_block_alignment = false;
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
m_text_from = DynamicElementTextItem::TextFrom(
@@ -431,13 +434,23 @@ bool PartDynamicTextField::frame() const
return m_frame;
}
/**
@brief PartDynamicTextField::setTextWidth
Set the width of this text (-1 = automatic width). The point of the text
chosen by its alignment stays in place, as when the text changes: a
right-aligned or centred field no longer grows to the right only, and
undoing a width change puts it back where it was.
@param width
*/
void PartDynamicTextField::setTextWidth(qreal width) {
prepareAlignment();
this -> document() -> setTextWidth(width);
//Adjust the width, to ideal width if needed
if(width > 0 && document() -> size().width() > width)
document() -> setTextWidth(document() -> idealWidth());
finishAlignment();
m_text_width = document() -> textWidth();
emit textWidthChanged(m_text_width);
}