询问 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 的大小,否则它似乎是恒定的。
这个公式一般有效,但可能应该有一个专门的函数。
我有两个ColumnLayout,我希望它们可以滚动,但是滚动条不显示。如果我删除一列,它就会显示出来。
代码:
ApplicationWindow {
id: applicationWindow1
visible: true
width: 400
height: 500
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
Item {
id : scroll;
anchors.centerIn: parent
}
ScrollView {
anchors.left: parent.left
anchors.top : parent.top
id:col1
width: 240
height: 618
anchors.leftMargin: 0
anchors.topMargin: 0
contentItem : fl0
frameVisible :true
ColumnLayout {
id:fl0
anchors.fill:parent
Rectangle{
width:200
height:200
color : "#585ef3"
}
Rectangle{
width:200
height:200
color : "#585ef3"
} …Run Code Online (Sandbox Code Playgroud) 我正在 QML 中创建一个自定义类型,其Column内部有一个GroupBox. 当该类型的用户向其中添加组件时CustomType,它们应该位于Column,而不是GroupBox。如何在不制作额外包装文件的情况下实现这一点?
//CustomType.qml
GroupBox {
Column {
}
}
//Main.qml
CustomType {
CheckBox {//This should be inside the Column of the GroupBox in CustomType
}
}
Run Code Online (Sandbox Code Playgroud) 我使用Qt Quick Controls 2时出现弹出窗口大小行为的问题.当我将ListView作为弹出窗口的contentItem时,弹出窗口大小为零.一些重现问题的示例代码:
import QtQuick 2.4
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
id: window
visible: true
width: 800
height: 600
Button {
text: "open popup"
onClicked: popup.open()
}
Popup {
id: popup
x: (window.width - width) / 2
y: window.height / 6
width: contentWidth
height: contentHeight
contentItem: ListView {
width: contentWidth
height: contentHeight
model: ListModel {
ListElement {
name: "Apple"
cost: 2.45
}
ListElement {
name: "Orange"
cost: 3.25
}
ListElement {
name: "Banana"
cost: 1.95
} …Run Code Online (Sandbox Code Playgroud) http://doc.qt.io/qt-5/qtqml-qmlmodule.html
QtQml和QtQuick似乎是不同的东西,这就是为什么有两个单独的import语句.
import QtQml 2.2
import QtQuick 2.3
QtQml和QtQuick之间有什么区别,在哪些现实案例中应该使用它们?