Qt Fast very slow painting

I just started looking at Qt Quick, and I have a very simple program, essentially the same as when running a Qt Quick Controls application.

The problem is that when I try to resize the window it takes a very long time. This can be seen .gif

below.

Problem

The only information I could find on the internet about people having a similar problem was that you could use the QML Profiler to find where the crash is happening and sometimes due to the debugger. So below you can see the QML profiler and the gif was captured in release mode.

enter image description here

As far as I can tell, the animation is blocking the GUI thread that is causing rendering or redrawing, but I'm not sure what is causing it.

I would appreciate any help in solving the problem.

And not much code.

Test.pro

QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
DEFINES += QT_DEPRECATED_WARNINGS
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

      

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

      

main.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: tabBar.currentIndex

        Page1 {
            Label {
                text: qsTr("First page")
                anchors.centerIn: parent
            }
        }

        Page {
            Label {
                text: qsTr("Second page")
                anchors.centerIn: parent
            }
        }

        Page {
            Label {
                text: qsTr("Third page")
                anchors.centerIn: parent
            }
        }
    }

    footer: TabBar {
        id: tabBar
        currentIndex: swipeView.currentIndex
        TabButton {
            text: qsTr("First")
        }
        TabButton {
            text: qsTr("Second")
        }
        TabButton {
            text: qsTr("Third")
        }
    }
}

      

Page1.qml

import QtQuick 2.7

Page1Form {
    button1.onClicked: {
        console.log("Button Pressed. Entered text: " + textField1.text);
    }
}

      

Page1Form.ui.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

Item {
    property alias textField1: textField1
    property alias button1: button1

    RowLayout {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.topMargin: 20
        anchors.top: parent.top

        TextField {
            id: textField1
            placeholderText: qsTr("Text")
        }

        Button {
            id: button1
            text: qsTr("Press Me")
        }
    }
}

      


Features: Windows 10, Qt 5.9, MSVC 2017


Qt Forum Cross Post

+3


source to share


3 answers


This Qt Bug has been fixed recently since 5.9.2: https://bugreports.qt.io/browse/QTBUG-59893



Did this solution help solve this problem?

+1


source


I think you have this problem because software rendering is used under the hood. So it takes quite a long time. Therefore, to enable hardware rendering, you need to install the ANGLE drivers. Your profiled image states that the swap operation is running all the time, so it is actually copying all pixels from the CPU to the GPU, which is why you see this lag. I disagree with @dtech that it won't help you. I have used ANGLE drivers to render fairly complex 3D GL scenes on Windows, so QT is capable of this, I'm sure



0


source


When resizing the qml window, you need to reevaluate the size bindings. Therefore, anything that changed the size or anchor properties needs to be recalculated. As far as I know, QT uses openGL as its default renderer. When the window is resized, the openGL buffer also needs to be resized and the full graphics editor needs to be repainted. But before this happens, individual elements must first be transferred if their size changes. Qml stores the visible elements in textures so that the elements resize the textures to be recreated ...

There are probably even more things going on depending on what elements you use or how your script is created or how your parties are composed.

If you want to debug the graph scene, you can do so by setting enviroment vars. For example, you can make changes to random colors by setting

QSG_VISUALIZE=changes

      

More on Qt Quick Scene Graph Renderer here.

-1


source







All Articles