- Timestamp:
- Apr 3, 2020 11:35:24 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichTextLabel.cpp
r82968 r83523 17 17 18 18 /* Qt includes: */ 19 #include <QtMath> 19 20 #include <QUrl> 20 21 #include <QVBoxLayout> … … 115 116 /* Get corresponding QTextDocument: */ 116 117 QTextDocument *pTextDocument = m_pTextEdit->document(); 117 /* Adjust text-edit size: */ 118 pTextDocument->adjustSize(); 119 /* Get corresponding QTextDocument size: */ 120 QSize size = pTextDocument->size().toSize(); 118 119 // WORKAROUND: 120 // Ok, here is the trick. In Qt 5.6.x initial QTextDocument size is always 0x0 121 // even if contents present. To make QTextDocument calculate initial size we 122 // need to pass it some initial text-width, that way size should be calualated 123 // on the basis of passed width. No idea why but in Qt 5.6.x first calculated 124 // size doesn't actually linked to initially passed text-width, somehow it 125 // always have 640px width and various height which depends on currently set 126 // contents. So, we just using 640px as initial text-width. 127 pTextDocument->setTextWidth(640); 128 129 /* Now get that initial size which is 640xY, and propose new text-width as 4/3 130 * of hypothetical width current content would have laid out as square: */ 131 const QSize oldSize = pTextDocument->size().toSize(); 132 const int iProposedWidth = qSqrt(oldSize.width() * oldSize.height()) * 4 / 3; 133 pTextDocument->setTextWidth(iProposedWidth); 134 135 /* Get effective QTextDocument size: */ 136 const QSize newSize = pTextDocument->size().toSize(); 121 137 122 138 /* Set minimum text width to corresponding value: */ 123 setMinimumTextWidth(m_iMinimumTextWidth == 0 ? size.width() : m_iMinimumTextWidth);139 setMinimumTextWidth(m_iMinimumTextWidth == 0 ? newSize.width() : m_iMinimumTextWidth); 124 140 }
Note:
See TracChangeset
for help on using the changeset viewer.