有没有办法让qml应用程序的窗口透明?
我正在寻找有关如何使用qml绘制简单形状的详细说明,同时使应用程序的窗口透明,以及背景.一个工作源代码演示将是非常棒的.
我有一个MouseArea,我想开始居中,然后按下上/下/左/右键后有一个绝对位置.我的问题是我不知道如何清除MouseArea上的锚点,以便我可以指定一个绝对位置:
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
id: screen
width: 360
height: 360
visible: true
Rectangle {
anchors.fill: parent
states: [
State {
name: "moved"
AnchorChanges {
target: mouseArea
anchors.bottom: undefined
anchors.left: undefined
anchors.right: undefined
anchors.top: undefined
}
}
]
MouseArea {
id: mouseArea
anchors.centerIn: parent
width: 250
height: 250
focus: true
onClicked: console.log("clicked!")
onPositionChanged: console.log("position changed!")
function moveMouseArea(x, y) {
mouseArea.x += x;
mouseArea.y += y;
mouseArea.state = "moved";
mouseAreaPosText.text = 'Mouse area was moved... new pos: …
Run Code Online (Sandbox Code Playgroud) Component
和Item
QML有什么区别?这里的文档并不完全清楚.用作多个小部件的容器的首选类型是什么?可以替换Rectangle
吗?
例如,以下声明的区别是什么:
Item {
id: itemWidget
Rectangle { id: one }
Rectangle { id: two }
}
Run Code Online (Sandbox Code Playgroud)
和
Component {
id: componentWidget
Rectangle { id: one }
Rectangle { id: two }
}
Run Code Online (Sandbox Code Playgroud)
为什么我们通常Component
在宣布时使用delegate
?
我正在尝试从QML中的ListView访问角色.基本上,我在我的QML中有这个:
ListView {
id: myId
model: myModel
delegate: Item {
Text {
text: model.text
}
Text {
text: model.moreText
}
}
}
Run Code Online (Sandbox Code Playgroud)
myModel
是一个QAbstractListModel实现.QML部分是可重用的组件,因此模型可以具有各种数据类型的任意数量的不同角色.我想要做的是绑定currentItem
ListView属性的给定角色的值.换句话说,我想Component
在页面上有一些可以将属性绑定到ListView中当前选定项目的其他内容,如下所示:
Text {
text: myId.currentItem.text // Or myId.currentItem.model.text (or something similar)
}
Run Code Online (Sandbox Code Playgroud)
请记住,我需要这个一般可用,因为我将为许多模型类型做很多事情,我试图不为每个模型和ListView编写那种自定义代码.
看起来访问当前所选项目的属性应该很简单,但据我所知,这是不可能的.当只有一个角色时,模型似乎被区别对待,这个问题更加复杂.我的意思是,有时您通过model.roleName
而不是只使用一个角色来访问您的角色modelData
.
如果有人有任何建议,我会非常感激.非常感谢!
编辑
我找到了这个:
http://comments.gmane.org/gmane.comp.lib.qt.qml/1778
但是,这似乎对我没用.当我尝试在我的QML脚本中使用数据时,我遇到类型错误,并且没有可用的类型转换,所以我不知道该怎么做.欢迎任何建议!
谢谢!
插口
我想对以下代码做一些similer:
//test.qml
import QtQuick 1.0
Item
{
var globalforJs =10;
function increment() // JavaScript function
{
globalforJs++;
}
....
QML Code
Run Code Online (Sandbox Code Playgroud)
我们可以使用全局变量QML file
并从JavaScript函数访问它吗?
我想知道是否可以使用(几个)不同的代表进行QML ListView
.
根据ListView
模型中的单个对象,我想用不同的委托来可视化对象.
这段代码解释了我想要实现的目标:
main.qml
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2
ApplicationWindow {
title: qsTr("Hello World")
width: 640
height: 480
visible: true
ListModel {
id: contactsModel
ListElement {
name: "Bill Smith"
position: "Engineer"
}
ListElement {
name: "John Brown"
position: "Engineer"
}
ListElement {
name: "Sam Wise"
position: "Manager"
}
}
ListView {
id: contactsView
anchors.left: parent.left
anchors.top: parent.top
width: parent.width
height: parent.height
orientation: Qt.Vertical
spacing: 10
model: contactsModel
delegate: { …
Run Code Online (Sandbox Code Playgroud) 我的应用程序是使用QML + JS制作的,我希望创建一个循环进度条小部件.我可以使用QML矩形创建圆,并将其半径设置为等于宽度/ 2,使其成为圆形.如何创建进度条呢?
我打算实现以下模型.
qml ×10
qt ×5
qt-quick ×3
javascript ×2
listview ×2
qtquick2 ×2
c++ ×1
delegates ×1
position ×1
roles ×1
transparent ×1
ubuntu-touch ×1
wpf ×1
xaml ×1