[英]Qt Quick very slow painting
我剛剛開始研究Qt Quick,我有一個非常基本的程序,基本上與啟動Qt Quick Controls應用程序項目時相同。
問題是,當我嘗試調整窗口大小時,需要很長時間才能完成。 這可以在下面的.gif
中看到。
我可以在網上找到關於遇到類似問題的人的唯一信息是,您可以使用QML Profiler查找生成延遲的位置,有時這是由調試器引起的。 所以下面你可以看到QML探查器和gif是在發布模式下錄制的。
據我所知,動畫是鎖定GUI線程,這導致渲染或重新繪制緩慢,但我不知道是什么導致它。
我很感激任何幫助解決問題。
並沒有太多的代碼。
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")
}
}
}
規格: Windows 10,Qt 5.9,MSVC 2017
最近這個Qt Bug被修復了,因為5.9.2: https : //bugreports.qt.io/browse/QTBUG-59893
此修復程序是否解決了此問題?
我認為你有這個問題,因為軟件渲染是在幕后使用的。 所以需要很長時間。 因此,要啟用硬件渲染,您需要安裝ANGLE驅動程序。 您的分析圖片表明交換操作一直在進行,因此這實際上是將所有像素從CPU復制到GPU,這就是您看到這種滯后的原因。 我不同意@dtech它不會幫助你。 我使用ANGLE驅動程序在Windows上渲染相當復雜的GL 3D場景,所以QT能夠做到這一點,我相信
在窗口調整大小時,qml必須重新評估大小的綁定。 因此,需要重新計算改變大小或具有錨屬性的所有內容。 據我所知,QT使用openGL作為默認渲染器。 在窗口調整大小時,緩沖區openGL渲染需要調整大小,並且需要重新繪制完整的場景圖。 但在此之前,如果單個元素的大小發生變化,則需要先重新渲染單個元素。 Qml在紋理中存儲可見元素,因此必須重新創建元素大小調整紋理...
可能會發生更多事情,具體取決於您使用的元素或構建場景圖的方式或批次的組成方式。
如果要調試場景圖,可以通過設置環境變量來實現。 例如,您可以通過設置以隨機顏色進行更改
QSG_VISUALIZE=changes
有關Qt Quick Scene Graph Renderer的更多信息,請點擊這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.