标签: qt-quick

具有方向的QML渐变

QML渐变仅允许在矩形中从上到下.该文件说,它必须通过旋转和裁剪的组合来完成.

我刚刚开始学习QML(和HTML/CSS的经验很少).这是我的代码,我认为可以更好地改进:

import QtQuick 1.0

Rectangle {
    width: 400; height: 400;

    Rectangle {
    width: 567; height: 567;

    gradient: Gradient {
            GradientStop {
        position: 0.0;
        color: "white";
        }
            GradientStop {
        position: 1.0;
        color: "blue";
        }
    }
    x: 116.5;
    transformOrigin: Item.Top;
    rotation: 45.0;
    }
}
Run Code Online (Sandbox Code Playgroud)

你能否建议一下这方面有什么更好的方法?

qt gradient qml qt-quick

6
推荐指数
3
解决办法
8278
查看次数

使用指定的属性从C++创建QML对象

从C++动态实例化QML对象已有详细记录,但我找不到的是如何使用为其属性预先指定的值来实例化它.

例如,我正在SplitView从C++ 创建一个稍微修改过这样的:

QQmlEngine* engine = QtQml::qmlEngine( this );
QQmlComponent splitComp( engine, QUrl( "qrc:/qml/Sy_splitView.qml" ) );
QObject* splitter = splitComp.create();

splitter->setProperty( "orientation", QVariant::fromValue( orientation ) );
Run Code Online (Sandbox Code Playgroud)

我的问题是,指定orientationSplitView 它被实例化会导致它的内部布局打破.那么,有没有创造的方式SplitVieworientation已经规定?

或者,我可以SplitView在单独的文件中创建水平和垂直版本,并在运行时实例化相应的版本- 但这不太优雅.

更新

我找到了QQmlComponent::beginCreate(QQmlContext* publicContext):

QQmlEngine* engine = QtQml::qmlEngine( this );
QQmlComponent splitComp( engine, QUrl( "qrc:/qml/Sy_splitView.qml" ) );
QObject* splitter = splitComp.beginCreate( engine->contextForObject( this ) );

splitter->setProperty( "orientation", QVariant::fromValue( orientation ) );
splitter->setParent( parent() );
splitter->setProperty( …
Run Code Online (Sandbox Code Playgroud)

c++ qt qml qt-quick

6
推荐指数
1
解决办法
4981
查看次数

错误:QOpenGLShader:无法创建着色器 - 使用Qt5.2编译QtQuick应用程序时Mingw OpenGL

我已经下载并安装了"Qt 5.2 mingw(opengl和x86)"版本.当我用这个版本的Qt运行Qt项目时,没有问题.但是当我运行Qt Quick应用程序时,程序崩溃并跟随消息登录调试:

getProcAddress: Unable to resolve 'glGenRenderbuffers'
getProcAddress: Unable to resolve 'glGenRenderbuffersOES'
getProcAddress: Unable to resolve 'glGenRenderbuffersARB'
getProcAddress: Unable to resolve 'glGenRenderbuffersEXT'
getProcAddress: Unable to resolve 'glBindRenderbuffer'
getProcAddress: Unable to resolve 'glBindRenderbufferOES'
getProcAddress: Unable to resolve 'glBindRenderbufferARB'
getProcAddress: Unable to resolve 'glBindRenderbufferEXT'
getProcAddress: Unable to resolve 'glRenderbufferStorage'
getProcAddress: Unable to resolve 'glRenderbufferStorageOES'
getProcAddress: Unable to resolve 'glRenderbufferStorageARB'
getProcAddress: Unable to resolve 'glRenderbufferStorageEXT'
getProcAddress: Unable to resolve 'glGenRenderbuffers'
getProcAddress: Unable to resolve 'glGenRenderbuffersOES'
getProcAddress: Unable to resolve 'glGenRenderbuffersARB'
getProcAddress: …
Run Code Online (Sandbox Code Playgroud)

opengl qt qml qt-quick qt5

6
推荐指数
1
解决办法
7178
查看次数

C++/QML项目兼容Qt 4(QtQuick 1.x)和Qt 5(QtQuick 2.x)

在编写不使用QML并且不依赖于新的Qt 5功能的Qt应用程序时,我们可以使用Qt 4和Qt 5编译它(除了少数源不兼容性).

当我们想要使用Qt 5功能但希望回归到同等但效率较低的Qt 4解决方案时,我们可以简单地使用an #if来检查Qt版本,例如使用新的QStringLiteral但是QString::fromUtf8在使用Qt 4编译时回落.

我们怎么能用QtQuick做同样的事情?请注意,有可能使用QDeclarativeViewQtQuick 1.xQt中5,但不会使用Qt的从5新场景图仅1.x被支持QDeclarativeView,只2.x支持在QQuickView,即使我不使用快速2.0中引入的功能.

我想要的是:

  • 用Qt 4编译时,请QDeclarativeView和朋友一起使用; 在QML中:import QtQuick 1.x
  • 使用Qt 5编译时,请使用新QQuickView朋友; 在QML中:import QtQuick 2.x
  • 只有一组QML文件,但没有一个用于QtQuick 1.x和另一个用于QtQuick 2.x

关于C++部分,这似乎很容易.在Qt 4中,我们可以简单地添加:

#include <QApplication>
#include <QDeclarativeView>
#include <QDeclarativeEngine>
typedef QApplication QGuiApplication;
typedef QDeclarativeView QQuickView;
Run Code Online (Sandbox Code Playgroud)

然后在Qt 4和Qt 5中使用QGuiApplication,QQuickView等等.但是当QML文件包含导入声明时QtQuick,我无法添加一个#if来决定1.x和2.x. 是否有正式的方法,比方说,添加一个别名 …

c++ qt qml qt-quick qtquick2

6
推荐指数
1
解决办法
1854
查看次数

使用Qt Quick创建可伸缩,有光泽/闪亮的按钮

我想用Qt Quick创建下面的光泽按钮(最好是纯QML,没有C++):

有光泽的按钮

它需要是可扩展的,所以我不能使用PNG等.

我的代码到目前为止:

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

ApplicationWindow {
    id: window
    color: "#cccccc"
    width: 200
    height: 200

    Button {
        id: button
        width: Math.min(window.width, window.height) - 20
        height: width * 0.3
        anchors.centerIn: parent
        text: "Button"

        style: ButtonStyle {
            background: Rectangle {
                gradient: Gradient {
                    GradientStop {
                        position: 0
                        color: "#bbffffff"
                    }
                    GradientStop {
                        position: 0.6
                        color: "#00c0f5"
                    }
                }

                border.color: "grey"
                border.width: height * 0.05
                radius: height / 5
            }

            label: Label {
                text: button.text …
Run Code Online (Sandbox Code Playgroud)

qt button qml qt-quick qtquickcontrols

6
推荐指数
1
解决办法
3243
查看次数

在Qt中将原始OpenGL渲染为QML UI的两种方法的比较

根据这篇文章,有两种主要的方法可以将原始OpenGL渲染成一个应用程序,其UI由QtQuick的场景图管理.简而言之,他们(根据我的理解):

  • 在手写代码中调用原始OpenGL方法,该代码通过QtQuick公开的一些API连接到场景图的渲染循环中.
  • 将场景的原始OpenGL部分渲染为QQuickFramebufferObject,它被视为场景图中的一个组件,并且自身呈现为纹理.

这两种方法有哪些优点/缺点?

opengl qt qml qt-quick

6
推荐指数
1
解决办法
1254
查看次数

如何在QML中创建没有标题栏但带有关闭/最小化/最大化按钮的窗口?

我想创建一个没有标题栏,但具有本机关闭,最小化和最大化按钮的应用程序。这是布局的意图:

在Mac上看起来如何

该应用程序是使用Go和QML构建的。我可以通过添加以下内容来删除标题栏:

flags: Qt.FramelessWindowHint | Qt.Window
Run Code Online (Sandbox Code Playgroud)

但这意味着我必须重新创建各种本机行为,例如窗口移动和调整大小。我还手动重新创建了关闭/最小化/全屏按钮,但这意味着我失去了各种本机OS行为,例如窗口中的窗口捕捉或Mac上的zoom选项。

有一个更好的方法吗?是否有可能至少创建本机的max-min-close按钮,而不是从头开始构建它?

谢谢大家

user-interface go qml qt-quick qtquick2

6
推荐指数
1
解决办法
3341
查看次数

Raspberry Pi上未安装模块"QtQuick.Controls"

我正在尝试使用qt5(5.3.2)在运行Raspbian-Jessie的Raspberry pi 3上编译一些qml.
我设法运行一些简单的东西但现在我需要使用QtQuick.Controls所以我添加import QtQuick.Controls 1.0到我的qml 文件但是当我尝试运行它时,我收到此错误消息:module "QtQuick.Controls" is not installed
Qt安装在以下文件夹中/usr/lib/arm-linux-gnueabihf/qt5/(它是自动检测到的)所以我去那里发现QtQuick Controls实际上在那里(中[path to qt]/qml/QtQuick/Controls)

我是否需要做一些实际的安装?
我试图添加/usr/lib/arm-linux-gnueabihf/qt5/qml/QtQuick/Controls,QML_IMPORT_PATH但我仍然收到错误消息.
我也看过,我需要QtQuick 2.0 QtQuick.Controls工作,但是当我改变import QtQuick 1.0import QtQuick 2.0我得到一个module "QtQuick" version 2.0 is not installed
任何人都设法在树莓派使用QtQuick.Controls?
关于如何调试这个的任何建议?

qt-quick raspbian qtquickcontrols qt5.3

6
推荐指数
1
解决办法
2761
查看次数

具有"速度"和无限"循环"的QML动画

我正在尝试整理一个动画,我可以在其中指定速度(而不是持续时间),并且永远循环.我想出了两个不起作用的例子:

FirstTry.qml

import Qt 4.7

Rectangle {
  width: 100; height: 100
  Text {
    text: "hello"
    NumberAnimation on x {
      to: 50;
      loops: Animation.Infinite;
      duration: 50 * Math.abs(to - from)
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

hello在屏幕上疯狂时得到以下运行时警告(足够公平).

QDeclarativeExpression: Expression "(function() { return 50 * Math.abs(to - from) })" depends on non-NOTIFYable properties: 
    QDeclarativeNumberAnimation::to
    QDeclarativeNumberAnimation::from
Run Code Online (Sandbox Code Playgroud)

SecondTry.qml

import Qt 4.7

Rectangle {
  width: 100; height: 100
  Text {
    text: "hello"
    SmoothedAnimation on x {
      to: 50;
      loops: Animation.Infinite;
      velocity: 50
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这更像是一种谜 …

qt qml qt-quick

5
推荐指数
1
解决办法
5106
查看次数

QML翻译

我尝试在QML中使用翻译.我开了一个新项目QtQuick项目,我选择QtQuick Componenets for Symbian作为QtQuick应用程序类型.Qt Creator创建了一个包含所有标准文件的应用程序源代码树(main.cpp,main.qml,mainpage.qml ...)

MainPage.qml非常简单:

import QtQuick 1.1
import com.nokia.symbian 1.1

Page {
    id: mainPage
    Text {
        anchors.centerIn: parent
        text: qsTr('Hello world!')
        color: platformStyle.colorNormalLight
        font.pixelSize: 20
    }
}
Run Code Online (Sandbox Code Playgroud)

我的main.cpp文件看起来像这样实现QTranslator:

#include "qmlapplicationviewer.h"
#include <QTranslator>
#include <QPushButton>
#include <QDebug>

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    QTranslator* translator = new QTranslator;

    qDebug()<<"Translating: "<<translator->load(QString("qml/International/inter_en"));

    app->installTranslator(translator);

    //QPushButton hello(QPushButton::tr("Hello world!"));
    //   hello.resize(100, 30);

    //   hello.show();

    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    viewer->setMainQmlFile(QLatin1String("qml/International/main.qml"));
    viewer->showExpanded();

    return app->exec();
}
Run Code Online (Sandbox Code Playgroud)

然后我运行lupdate mainpage.qml -ts inter_en.ts,我用语言学家来翻译POSIX表达式"Hello world!" 别的东西只是测试它正在翻译.然后我用语言学家创建了inter_en.qm文件.

但是当我在模拟器上运行应用程序时,我不会得到"Hello world!" …

c++ translation symbian qml qt-quick

5
推荐指数
1
解决办法
2027
查看次数