要为Qt制作类似Android ViewPager,我使用如下的列表视图:
ListView {
id: myListViewArticle
anchors.fill: parent
focus: true
highlightRangeMode: ListView.StrictlyEnforceRange
orientation: ListView.Horizontal
snapMode: ListView.SnapOneItem
model: modelArticles
delegate: articleDelegate
}
Run Code Online (Sandbox Code Playgroud)
和Flickable作为其代表:
Component {
id: articleDelegate
Item {
id: item
width: 480; height: 800
Flickable {
id: mainScrollView
contentHeight: 1500
contentWidth: parent.width
anchors.fill: parent
clip: true
Text {
id: idArticleContent
text: articleContent
width: parent.width
font.pixelSize: 20
font.bold: true; color: "black"
wrapMode: Text.Wrap
}
}
ScrollDecorator {
flickableItem: mainScrollView
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是在为listview填充数据之后,我看到Flickable无法滚动(在Verticle中).
谁能告诉我如何在列表视图中滚动Flickable项目.非常感谢你的帮助.
我正在尝试使用 QML 和 WebEngineView 组件为 Ubuntu 14.04 的桌面制作一个简单的网络浏览器。该应用程序将在带有触摸板的设备上运行,因此最好使 WebEngineView 中显示的内容可滑动。
我试图这样做,但它不起作用:
...
WebEngineView {
id: webView
url: "http://google.com"
width: parent.width
height: winternet.height-navigationBar.height-iStatusBar.height-iBackButton.height
anchors.top: navigationBar.bottom
MouseArea {
anchors.fill: parent
drag.target: parent.data
}
onLinkHovered: {
webView.url = hoveredUrl
}
}
...
Run Code Online (Sandbox Code Playgroud)
如果您对此有任何想法或经验,请提供帮助!
我注意到继承Flickable.
我有两个文件,Comp.qml和main.qml. 这个想法是一个Comp对象的任何子级都将是Flickableunder 的子级Comp。我已经默认使用内容
default property alias contents: flickable.children
Run Code Online (Sandbox Code Playgroud)
但结果却很奇怪。
Comp.qml
Rectangle {
id: comp;
anchors.fill: parent
default property alias contents: flickable.children; // alias a default property
property int contentHeight: comp.height;
Flickable {
id: flickable;
anchors.fill: parent;
contentHeight: comp.contentHeight;
}
}
Run Code Online (Sandbox Code Playgroud)
主文件
Rectangle {
id: root;
width: 400;
height: 400;
Comp {
contentHeight: 800;
Rectangle { // <-- this rectangle should be a child of Flickable
width: 800; …Run Code Online (Sandbox Code Playgroud) 我想使Flickable区域中的Scrollbar.vertical始终可见。当前,单击后可见。文本区域也与滚动条重叠。我如何在以下QML代码中用文本区域分隔滚动条
import QtQuick 2.0
import QtQuick.Controls 2.0
Flickable {
id: flickable
anchors.fill: parent
TextArea.flickable: TextArea {
text: "The Qt QML module provides a framework for developing applications and libraries with the QML language.
It defines and implements the language and engine infrastructure, and provides an API to enable application developers to
extend the QML language with custom types and integrate QML code with JavaScript and C++.
The Qt QML module provides both a QML API and a C++ API.
Note …Run Code Online (Sandbox Code Playgroud) 我正在使用Flickable嵌入在Rectangle中的.矩形底部有一个按钮.我的要求是当我按下按钮时,我的Flickable将移动到顶部.它几乎像HTML中的#TOP.有人知道如何实现这个目标吗?
询问 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 的大小,否则它似乎是恒定的。
这个公式一般有效,但可能应该有一个专门的函数。