【问题标题】:QT6.1 - Qml Why does the ProgressBar not have an animation corresponding to the indeterminate property?QT6.1 - Qml 为什么ProgressBar没有对应indeterminate属性的动画?
【发布时间】:2021-09-19 02:28:41
【问题描述】:

正如标题所说,我将 ProgressBar 的 indeterminate 属性设置为 True,但他没有任何动画。

就像这样:

但是: 我用的是默认项目,代码很简单。

我想知道indeterminate本身是没有动画还是有什么问题?

感谢您的帮助。

顺便说一句,这是我第一次在这里寻找答案,所以我希望这是一次愉快的经历:)

版本: Qt6.1.1 MinGW 64位(默认调试版本)

代码如下:

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15

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

    ProgressBar{
        id: proBar
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        height: 20
        from: 1
        to: 1
        indeterminate: true
    }
}

是的,这就是我的 qml 中的所有代码。文件的其余部分没有改变一个字

【问题讨论】:

  • 我会尝试另一种风格(例如材质):doc.qt.io/qt-5/…。如果它适用于其他样式,那么它可能是一个错误,可以在这里报告:bugreports.qt.io

标签: qt qml qt6


【解决方案1】:

我认为这与您的 Qt 版本有关,我在 Qt 中测试了您的代码。 我使用Qt5.14GCC 编译器,结果是这样的:

用于添加样式:

main.cpp 里放这个

QQuickStyle::setStyle("Universal");

像这样:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>

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

    QGuiApplication  app(argc, argv);

    QQuickStyle::setStyle("Universal");

    QQmlApplicationEngine  engine;
    const QUrl             url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl)
    {
        if (!obj && (url == objUrl))
        {
          QCoreApplication::exit(-1);
        }
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}

并在 .pro 文件中添加:

QT += quick quickcontrols2

修改后的代码

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Universal 2.12

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

    Universal.theme: Universal.Dark
    Universal.accent: Universal.Red
    ProgressBar{
        id: proBar
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: parent.top
        height: 70
        from: 1
        to: 1
        indeterminate: true
    }
}

【讨论】:

  • 感谢您的回答。现在空项目好了,但是我加了样式他就不行了……加了样式后,我是不是要自己实现这个效果?
  • 你是如何设置你的风格的?你设置了哪种风格?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
相关资源
最近更新 更多