我有 QQuickView 从 C++ 实例化组件的问题......这是我的代码:
类定义 ( vviewerqml.h):
class VViewerQml : public QObject
{
Q_OBJECT
public:
explicit VViewerQml(QSettings &systemSettings, QObject *parent = 0);
~VViewerQml();
protected slots:
void onViewStatusChanged(QQuickView::Status status);
protected:
QString _qmlFolder;
QQuickView _view;
};
Run Code Online (Sandbox Code Playgroud)
类实现(vviewerqml.cpp):
#include "vviewerqml.h"
VViewerQml::VViewerQml(QSettings &systemSettings, QObject *parent) :
QObject(parent)
{
// Initialize viewer reading from settings file
_qmlFolder = "/my/path/to/qml/files";
// Initialize the source
connect(&_view, SIGNAL(statusChanged(QQuickView::Status)),
this, SLOT(onViewStatusChanged(QQuickView::Status)));
_view.setSource(QUrl::fromLocalFile(QDir(_qmlFolder).filePath("Main.qml")));
// Show the viewer
_view.show();
}
VViewerQml::~VViewerQml()
{
// Close the viewer
_view.close(); …Run Code Online (Sandbox Code Playgroud) 在玩 QML 时,我注意到一个奇怪的行为。假设我有简单的 QML 代码:
Rectangle {
anchors.centerIn: parent
width:200
height:100
color:"yellow"
border.color: "green"
border.width: 10
rotation: 190
}
Run Code Online (Sandbox Code Playgroud)
结果:

图像看起来很差,尤其是边框。但是如果我添加radius: 1我会得到一个非常不同的图片:

现在看起来好多了。边框看起来也更平滑。顺便说一句,设置smooth属性什么都不做。看起来设置会radius开启一些内部平滑。所以我的问题 - 如何在smooth没有设置的情况下设置它radius?
我在 Debian 7 上使用 Qt 5.4
我有一个 qt 小部件应用程序。我想将开关控件添加到我的表单中。我添加到我的表单 QDeclarative 小部件并将此行添加到代码中,但没有显示任何内容。
ui->declarativeView->setSource(QUrl::fromLocalFile("test.qml"));
Run Code Online (Sandbox Code Playgroud)
这是qml文件的内容(我把这个文件加到资源里了) 显示在qtcreator下resources/[project_name.qrc]/test.qml
import QtQuick 2.4
import QtQuick.Controls 1.3
Button{
text:aaaa
}
Run Code Online (Sandbox Code Playgroud)
我添加了专业文件:qt += declarative
我究竟做错了什么??
我正在使用 Qt 5.4.1 QtCreator 3.3.1。
我愿意使用 QML 中的 FileDialog,但事实证明它不适用于SaveAs情况(因为您不能指定不存在的文件名),而且对话框的感觉并不是真正现代或移动。
作为一种解决方法,我决定构建一个简单的MyFileDialog,如下所示:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
Popup
{
implicitWidth: window.width / 3 * 2
implicitHeight: window.height / 3 * 2
x: (window.width - width) / 2
y: 20
modal: true
focus: true
property alias title: popupLabel.text
contentItem: ColumnLayout
{
id: settingsColumn
spacing: 20
// Popup title.
Label
{
id: popupLabel
font.bold: true
anchors.horizontalCenter: parent.horizontalCenter
}
// File path.
TextField
{
id: field …Run Code Online (Sandbox Code Playgroud) 我有 4 个 qml 文件和一个 main.cpp 来加载 qml 文件。我是否可以为这 4 个 qml 文件创建 1 个 dll 文件。并在不同的应用程序中使用它,如果是这样如何做到这一点。
我将练习这个例子,为此我在Windows 7 机器上使用 Qt Creator 4.3.0创建了一个名为Main2的Qt Quick Console 2 应用程序项目。
main.qml的代码如下所示:
我在应用程序输出窗口中收到以下错误:
程序意外结束。
C:\Users\Abbasi\Documents\QML\Main2\Main2\build-Main2-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\Main2.exe 崩溃。
启动 C:\Users\Abbasi\Documents\QML\Main2\Main2\build-Main2-Desktop_Qt_5_9_0_MinGW_32bit-Debug\debug\Main2.exe ...
QML 调试已启用。仅在安全的环境中使用它。
请问路径有什么问题吗?
图像位于桌面上名为图像的文件夹中。如何将它们移动到项目下的文件夹中,请一步一步地说明?
例如,我正在寻找一种在多个QML文件之间共享只读值的简单方法。可以说我有一个label元素:
Label {
id: titleLabel
text: listView.currentItem ? listView.currentItem.text : "IDEAL Networks"
font.pixelSize: 20
elide: Label.ElideRight
horizontalAlignment: Qt.AlignLeft
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
color: red;
padding: {
left: 14
}
}
Run Code Online (Sandbox Code Playgroud)
该color和padding值需要在其他QML文件和同一文件的其他领域使用。
除了重新键入red和在多个位置14之外,还有一种方法可以创建包含这些值的共享库,从而使以后更容易进行全局更新?
*更新*
我已按照此处的说明进行操作:http : //doc.qt.io/qt-5/qtqml-modules-qmldir.html
但是,当导入自定义CustomStyles 1.0模块时,出现错误-未安装模块“ CustomStyles”。
//Style.qml with custom singleton type definition
pragma Singleton
import QtQuick 2.0
QtObject {
property int textSize: 20
property color textColor: "green"
}
// qmldir declaring the singleton type
module CustomStyles
singleton Style …Run Code Online (Sandbox Code Playgroud) 我在一个页面上有3个列表视图,我想创建一个ListView可以与每个列表一起使用的单个标题组件.
所以我有一个ListView:
ListView {
id: listOne
spacing: 5
header: headerComponent
model: ListOneModel
}
Run Code Online (Sandbox Code Playgroud)
它引用了以下标头组件:
Component {
id: headerComponent
Rectangle {
width: ListView.view.width
height: 50
Label {
text: "List One"
font.pixelSize: 20
elide: Label.ElideRight
width: ListView.view.width
padding: {
left: 14
}
background: Rectangle {
color: "red"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何使标题组件可重用,以便当我连接ListView到标题时,我还可以传入不同的标题?
我知道我可以更改标题组件并添加titleText属性,如下所示:
Component {
id: headerComponent
property string titleText: "My Title"
Rectangle {
width: ListView.view.width
height: 50
Label {
text: titleText
font.pixelSize: 20
elide: Label.ElideRight …Run Code Online (Sandbox Code Playgroud) 是否可以在一个页面中显示多个listView?
我有3个单独的列表视图,我想在一个页面上显示它们,我正在努力将它们列出来.它们彼此重叠.
布局的简单示例:
ListView {
id: listOne
property string headertitle: "list one header"
spacing: 5
header: headerComponent
model: ListOneModel
}
ListView {
id: listTwo
property string headertitle: "list two header"
spacing: 5
header: headerComponent
model: ListTwoModel
}
ListView {
id: listThree
property string headertitle: "list three header"
spacing: 5
header: headerComponent
model: ListThreeModel
}
Run Code Online (Sandbox Code Playgroud) 我有一个 css 动作,我想在 qml 中复制,如何在 QML 中制作按钮(或任何其他元素)动画以产生脉动效果,如以下 CSS:
@import "bourbon";
$n:6;
$w:20px;//dot size
$e:4;//dot margin factor
$hsl:160;//start color
$bg:#333;
html{
background:$bg;
height: 100%;
backface-visibility: hidden;
}
#c{
position: absolute;
top:50%;
left:50%;
margin-left: -(($n - 1)*($w + $w*$e))/2 - ($w/2);
}
@mixin shadow($b,$s,$sm,$c){
box-shadow:
0 0 8px 6px $c,
0 0 $b $s $bg,
0 0 $b ($s + $sm) $c;
}
.s{
width: $w;
height: $w;
border-radius: 50%;
cursor:pointer;
float: left;
@include transition(all .2s);
&:nth-child(n+2){
margin-left: $w*$e;
} …Run Code Online (Sandbox Code Playgroud)