Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What does QTextCharFormats QTextFormat::FontSizeAdjustment Property do?
Qt 6.11 is out! See what's new in the release blog

What does QTextCharFormats QTextFormat::FontSizeAdjustment Property do?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 270 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qt3.14
    wrote on last edited by qt3.14
    #1

    So I want to insert HTML with QTextCursor::insertHTML.
    It allows for basic HTML styling, but it appears that the <font size=5> tag is a bit unclear.
    Looking into the source code:

    void QTextHtmlParser::applyAttributes(const QStringList &attributes)
    {
        // local state variable for qt3 textedit mode
        bool seenQt3Richtext = false;
        QString linkHref;
        QString linkType;
        if (attributes.count() % 2 == 1)
            return;
        QTextHtmlParserNode *node = &nodes.last();
        for (int i = 0; i < attributes.count(); i += 2) {
            QString key = attributes.at(i);
            QString value = attributes.at(i + 1);
            switch (node->id) {
                case Html_font:
                    // the infamous font tag
                    if (key == QLatin1String("size") && value.size()) {
                        int n = value.toInt();
                        if (value.at(0) != QLatin1Char('+') && value.at(0) != QLatin1Char('-'))
                            n -= 3;
                        node->charFormat.setProperty(QTextFormat::FontSizeAdjustment, n);
                    } else if (key == QLatin1String("face")) {
                        if (value.contains(QLatin1Char(','))) {
                            const QStringList values = value.split(QLatin1Char(','));
                            QStringList families;
                            for (const QString &family : values)
                                families << family.trimmed();
                            node->charFormat.setFontFamilies(families);
                            node->charFormat.setFontFamily(families.at(0));
                        } else {
                            node->charFormat.setFontFamily(value);
                        }
                    } else if (key == QLatin1String("color")) {
                        QColor c; c.setNamedColor(value);
                        if (!c.isValid())
                            qWarning("QTextHtmlParser::applyAttributes: Unknown color name '%s'",value.toLatin1().constData());
                        node->charFormat.setForeground(c);
                    }
                    break;
    

    It translates the size value into an int and sets the QTextFormat::FontSizeAdjustment property to that int.
    The enums description says "Specifies the change in size given to the fontsize already set using FontPointSize or FontPixelSize." What is the given FontSize, is it the defaultStyleSheets font? And if so how do I know if it is using Points or Pixels. Right now the only working values for that size tag are 1-7 which results in point sizes that are different from those values when printing the document onto pdf. I want to reliably set the point size.

    Ok it might have something to do with the html4 notation of that tag.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved