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)
你能否建议一下这方面有什么更好的方法?
从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)
我的问题是,指定orientation的SplitView 后它被实例化会导致它的内部布局打破.那么,有没有创造的方式SplitView与orientation已经规定?
或者,我可以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) 我已经下载并安装了"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) 在编写不使用QML并且不依赖于新的Qt 5功能的Qt应用程序时,我们可以使用Qt 4和Qt 5编译它(除了少数源不兼容性).
当我们想要使用Qt 5功能但希望回归到同等但效率较低的Qt 4解决方案时,我们可以简单地使用an #if来检查Qt版本,例如使用新的QStringLiteral但是QString::fromUtf8在使用Qt 4编译时回落.
我们怎么能用QtQuick做同样的事情?请注意,有可能使用QDeclarativeView与QtQuick 1.xQt中5,但不会使用Qt的从5新场景图仅1.x被支持QDeclarativeView,只2.x支持在QQuickView,即使我不使用快速2.0中引入的功能.
我想要的是:
QDeclarativeView和朋友一起使用; 在QML中:import QtQuick 1.xQQuickView朋友; 在QML中:import QtQuick 2.xQtQuick 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. 是否有正式的方法,比方说,添加一个别名 …
我想用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) 根据这篇文章,有两种主要的方法可以将原始OpenGL渲染成一个应用程序,其UI由QtQuick的场景图管理.简而言之,他们(根据我的理解):
这两种方法有哪些优点/缺点?
我想创建一个没有标题栏,但具有本机关闭,最小化和最大化按钮的应用程序。这是布局的意图:

该应用程序是使用Go和QML构建的。我可以通过添加以下内容来删除标题栏:
flags: Qt.FramelessWindowHint | Qt.Window
Run Code Online (Sandbox Code Playgroud)
但这意味着我必须重新创建各种本机行为,例如窗口移动和调整大小。我还手动重新创建了关闭/最小化/全屏按钮,但这意味着我失去了各种本机OS行为,例如窗口中的窗口捕捉或Mac上的zoom选项。
有一个更好的方法吗?是否有可能至少创建本机的max-min-close按钮,而不是从头开始构建它?
谢谢大家
我正在尝试使用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.0到import QtQuick 2.0我得到一个module "QtQuick" version 2.0 is not installed
任何人都设法在树莓派使用QtQuick.Controls?
关于如何调试这个的任何建议?
我正在尝试整理一个动画,我可以在其中指定速度(而不是持续时间),并且永远循环.我想出了两个不起作用的例子:
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)
这更像是一种谜 …
我尝试在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!" …