询问 Flickable.contentY 边界的正确方法是什么?我需要滚动条。
通过实验我发现
offsetY <= contentY <= offsetY + contentHeight - height
Run Code Online (Sandbox Code Playgroud)
其中 offsetY 可以计算为
var offsetY = contentY-Math.round(visibleArea.yPosition*contentHeight)
Run Code Online (Sandbox Code Playgroud)
offsetY 在应用程序开始时为零,除非调整 Flickable 的大小,否则它似乎是恒定的。
这个公式一般有效,但可能应该有一个专门的函数。
有没有办法在 QML 中创建所需的自定义属性?例如,类似于:
property required int numRows
Run Code Online (Sandbox Code Playgroud)
我想强制组件的用户传递某个属性,因为没有它组件将无法工作。
是否可以为文本编辑的特定行设置背景颜色(例如单击行时)?
我的 TextEdit 宽度为 500px,行数为 10 行。我将单击第 5 行,该行是空行,但我仍然想更改整行的背景颜色。是否可以?
我需要知道是否可以使用 Qt 和 Qml 开发完全定制的代码编辑器。
我想让 ScrollView 的滚动条比默认值更宽,但我看不到任何width属性,即使是ScrollViewStyle元素frame组件的一部分。
我部分成功地将 json 解析为我的 qml 应用程序,但只是部分成功。我可以通过 console.log() 很好地输出 countryCode 和 countryName,最终目标仍然是将 json 解析的数据附加到 listmodel。仍然无法输出带有年份和实际数据数据部分的 bigmac_index。
显然已经尝试了不同的解决方案并尝试应用主题的给定答案,但没有成功。希望从工作解决方案中受益:)
json 部分: [ { "countryCode": "fi", "countryName": "Finland", "bigmac_index": [ { "year": "2013", "data": "5.27" }, { "year": " 2012", "data": "4.55" }, { "year": "2011", "data": "5.38" } ] } ]
这是我正在使用的功能:
function request(url, callback) {
var xhr = new XMLHttpRequest();
console.log("xhr.send executed")
xhr.onreadystatechange = (function()
{
console.log("xhr readystate ", xhr.readyState)
if(xhr.readyState == 4 && xhr.status == 200)
{
console.log("readyState == 4, starting to …Run Code Online (Sandbox Code Playgroud) I'm unable to assign ExclusiveGroup to my checkable buttons.
ExclusiveGroup {
id: group
onCurrentChanged: {
if(current != null) {
console.info("button checked...no!")
current = null
//current.checked = false <--- also this
}
}
}
Column {
width: parent.width
spacing: 0
Button {
id: btnScan
flat: true
text: qsTr("But1")
width: parent.width
checkable: true
exclusiveGroup: group
}
Button {
id: btnWhiteList
flat: true
text: qsTr("But2")
width: parent.width
checkable: true
exclusiveGroup: group
}
}
Run Code Online (Sandbox Code Playgroud)
The documentation states clearly that Button does have exclusiveGroup property …
我有几个qml文件,每个文件都在我的应用程序中定义一个屏幕.有时,一个屏幕上的操作应该更改不同屏幕上的项目.现在我通过设置属性Item buttonId然后执行此操作
for (var i = 0; i < buttonId.parent.children.length; i++) {
buttonId.parent.children[i].state="inactive"
}
Run Code Online (Sandbox Code Playgroud)
是否可以直接访问不同文件中的项目/对象,例如通过他们的ID?
我正在用QML创建一个绘图组件.我的QML组件的结构如下所示:
Rectangle {
id: canvas
objectName: "myPlot"
Rectangle {
id: plot
PlotArea {
id: pa
} // this is my c++ QQuickItem
MouseArea {} // for handling interaction with the plot, like zooming
XAxis{}
YAXis{}
}
}
Run Code Online (Sandbox Code Playgroud)
这PlotArea是我的c ++课程.我需要从C++与这个QML组件进行交互,更准确地说,我需要调用一个成员函数PlotArea来向绘图中添加数据.通常的方法是使用findChild<QObject*>("objectName"),但由于组件将被重用,我不能给PlotArea和对象名称.
PlotArea如果我有指针,我该如何访问"myPlot"?我试过了
QObject *plot = rootObjects.value(0)->findChild<QObject*>("plotObject");
PlotArea * myplot = (plot->findChild<PlotArea*>("pa"));
Run Code Online (Sandbox Code Playgroud)
但这不起作用.但是,如果我这样做,那么上述方法是有效的
PlotArea {
id: pa
objectName: "pa"
} // this is my c++ QQuickItem
Run Code Online (Sandbox Code Playgroud)
但是我想知道这是否安全,因为在我的应用程序中会有服务PlotAreas,并且所有这些都有"pa"这个名字.
将对象从Qml传递给C++时,我传递对象本身或指向它的指针?示例:我有一个C++插槽,我从Qml文件中调用它并将参数传递给它.我传递给插槽,对象或指向它的指针是什么?