Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

qt - QML Canvas improperly rendered with QT_SCALE_FACTOR set

I have a Qt/QML program that runs on Ubuntu and on a Raspberry Pi 3B+. The program runs fine on both platforms however the Pi has a high DPI screen so I set a QT_SCALE_FACTOR to 1.3 on that device to make controls appear the right size. It works perfectly except for one thing: indicators on ComboBox and SpinBox controls are drawn the same size as if no QT_SCALE_FACTOR was set, and the rest of the rectangle they would fill if the QT_SCALE_FACTOR was applied is filled with random pixels. Setting a QT_SCALE_FACTOR on Ubuntu works without any issues.

I tried replacing the indicators with a custom one but I get the same result.

Leaving QT_SCALE_FACTOR unset produces correctly rendered indicators.

This is with Qt 5.13.2 and QtQuick.Controls 2.5 on Linux pi3 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l GNU/Linux

The pictures below illustrate the behavior with QT_SCALE_FACTOR=2:

ComboBox with defective custom indicator

SpinBox standard indicators

This is the code for the custom indicator in the first picture:

ComboBox {
    id: cb
...
    width: 200
...
    indicator: Canvas {
        id: canvas
        x: cb.width - width - cb.rightPadding
        y: cb.topPadding + (cb.availableHeight - height) / 2
        width: 12*2
        height: 8*2
        contextType: "2d"

        Connections {
            target: cb
            function onPressedChanged() { canvas.requestPaint(); }
        }

        onPaint: {
            var context = getContext("2d");
            context.reset();
            context.beginPath();
            context.moveTo(0, 0);
            context.lineTo(width, 0);
            context.lineTo(width / 2, height);
            context.closePath();
            context.fillStyle = cb.pressed ? "#17a81a" : "#21be2b";
            context.fill();
        }
    }
question from:https://stackoverflow.com/questions/65836687/qml-canvas-improperly-rendered-with-qt-scale-factor-set

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...