VirtualBox

Changeset 83523 in vbox for trunk/src


Ignore:
Timestamp:
Apr 3, 2020 11:35:24 AM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9669: QIRichTextLabel: More wise adjustSize technique based on own approach more close to QLabel than to QTextEdit; It's used to adjust assigned text size for better user experience.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIRichTextLabel.cpp

    r82968 r83523  
    1717
    1818/* Qt includes: */
     19#include <QtMath>
    1920#include <QUrl>
    2021#include <QVBoxLayout>
     
    115116    /* Get corresponding QTextDocument: */
    116117    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();
    121137
    122138    /* 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);
    124140}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette