slint icon indicating copy to clipboard operation
slint copied to clipboard

Font selection appears broken with Qt native style

Open inferiorhumanorgans opened this issue 2 years ago • 4 comments

$ uname -v
Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64

With only the Qt backend enabled setting the default-font-family property has no effect. With only the gl-all backend enabled fonts are selected as expected. The behavior is consistent across both system fonts (e.g. selecting Times New Roman) and fonts that are unknown to the system and imported via the slint file.

Edit: This may be a Qt issue not a platform specific one.

inferiorhumanorgans avatar Mar 08 '22 23:03 inferiorhumanorgans

With this slint:

import { Button, CheckBox, GroupBox, ListView, SpinBox, TextEdit } from "std-widgets.slint"; 

import "B612-Regular.ttf";

MainWindow := Window {

    width: 800px;
    height: 600px;

    default-font-family: "B612";

    GridLayout {
        Text {
            row: 0;
            col: 0;
            height: 200px;
            width: 400px;
            horizontal-alignment: center;
            color: black;
            text: "THE QUICK BROWN FOX (Text, 42 px)";
            font_size: 42px;
        }

        Button {
            row: 0;
            col: 1;
            height: 200px;
            width: 400px;
            font_size: 42px;
            text: "JUMPS OVER THE LAZY DOG (Button, 42 px)";
        }

        ListView {
            row: 1;
            col: 0;
            height: 200px;
            width: 400px;

            for data in [
                { text: "Blue", color: #0000ff, bg: #eeeeee},
                { text: "Red", color: #ff0000, bg: #eeeeee},
                { text: "Green", color: #00ff00, bg: #eeeeee},
                { text: "Yellow", color: #ffff00, bg: #222222 },
                { text: "Black", color: #000000, bg: #eeeeee },
                { text: "White", color: #ffffff, bg: #222222 },
                { text: "Magenta", color: #ff00ff, bg: #eeeeee },
                { text: "Cyan", color: #00ffff, bg: #222222 },
            ] : HorizontalLayout {
                CheckBox {
                    text: data.text;
                }
            }
        }

        SpinBox {
            row: 1;
            col: 1;
            value: 42;
            height: 200px;
            width: 400px;
        }

        GroupBox {
            height: 200px;
            width: 400px;
            row: 2;
            col: 0;
            title: "Group Box Title";
            Text {
                text: "Group Box Text";
                color: blue;
            }
        }

        TextEdit {
            width: 400px;
            height: 200px;
            text: "TextEdit";
        }
    }
}

As rendered with the Qt backend: qt-backend

As rendered with the GL backend: gl-backend

inferiorhumanorgans avatar Mar 09 '22 02:03 inferiorhumanorgans

Note that the Qt native style renders the widgets with the default QWidget font, so the font size has no effect for them. But that does not explain the bugs with the GL backend.

ogoffart avatar Mar 10 '22 22:03 ogoffart

Note that the Qt native style renders the widgets with the default QWidget font, so the font size has no effect for them.

Ah yes, we have a dummy property<length> font-size; in Button. We could construct appropriate QFontMetrics for it though and set a font on the QPainter before drawing (just like QPainter::begin(widget) sets the painter's font from the widget font).

But that does not explain the bugs with the GL backend.

Which ones do you see?

tronical avatar Mar 11 '22 07:03 tronical

@tronical For the Qt backend I'd expect the widgets to respect the font family value. With the GL backend it looks like the horizontal alignment is being ignored.

inferiorhumanorgans avatar Mar 14 '22 01:03 inferiorhumanorgans