- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我开始使用 QtQuick Controls 2.0。我有使用 C++ 的经验和少量的 Qt 经验,但我以前没有使用过 QML。
我有一个 TabBar
和一个 SwipeView
相互链接。我的意思是,当您在 TabBar
上选择一个页面时,SwipeView
会转到该页面。当您从 SwipeView
滑动到一个页面时,TabBar
会自行更新以反射(reflect)这一点。
作为学习练习,我决定创建一个将用户转到第二页的按钮。问题是我似乎无法找到一种方法来做到这一点而不会弄乱 TabBar
和 SwipeView
之间的链接。
下面的代码是我想出的最好的。它正确转到第二页,当我使用 TabBar
更改当前页面时,SwipeView
仍会更新。但是,滑动 到新页面不再更新 TabBar
。似乎将 tabBar.currentIndex
设置为 swipeView.currentIndex
只有在用冒号初始化时才具有按引用设置的效果。使用等号按值设置。我怎样才能移动到特定页面,同时仍然保持不变 swipeView.currentIndex == tabBar.currentIndex
?
// main.qml
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
SwipeView {
id: swipeView
anchors.fill: parent
currentIndex: tabBar.currentIndex
Page {
Button {
text: qsTr("Continue to Page 2")
onClicked: {
tabBar.currentIndex = 1;
// this next line merely sets tabBar.currentIndex to 1
tabBar.currentIndex = swipeView.currentIndex
}
anchors.centerIn: parent
width: text.implicitWidth
height: text.implicitHeight
}
}
Page {
Label {
text: qsTr("Second page")
anchors.centerIn: parent
}
}
}
footer: TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
TabButton {
text: qsTr("First")
}
TabButton {
text: qsTr( "Second")
}
}
}
C++ 代码只是 Qt Creator 为我提供的默认代码:
// main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
return app.exec();
}
最佳答案
为了在不破坏 currentIndex
绑定(bind)的情况下移动到下一页或上一页,您可以调用 incrementCurrentIndex()
或 decrementCurrentIndex()
, 分别。这些方法在 Qt 5.8 的 Qt Quick Controls 2.1 中引入。
鉴于 currentIndex
setter aka。 QQuickContainer::setCurrentIndex()
是一个slot,也可以从QML调用setCurrentIndex()
跳转到任意页面。这也不会破坏现有的绑定(bind)。
Button {
onClicked: tabBar.setCurrentIndex(1)
}
关于c++ - 转到特定页面后,如何将SwipeView的currentIndex设置为TabBar的currentIndex "by reference"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43578012/
我正在使用这个:https://github.com/nicklockwood/SwipeView 我在我的应用程序的 2 个不同位置使用它。 屏幕上的 30x30 图片大约 100kb 文件大小,这
如果我使用滑动 View ,我会遇到一些问题,并且我编写了以下代码: import QtQuick 2.6 import QtQuick.Window 2.2 import QtQuick.Contr
我正在尝试创建基于 SwipeView 元素的视差 View 。 QML 文档中的示例说明了如何使用 ListView 实现它: Image { id: background sour
我通过 viewpager 有一个带有两个不同 View ( fragment )的 swipeview。我现在想要这两个页面显示来自 sqllite 数据库的不同数据。问题是我无法弄清楚如何做到这一
我将尝试以非常清晰易懂的方式解释我的问题。 我目前在这里使用 SwipeView:http://jasonfry.co.uk/?id=23
我正在使用 jason fry 的 SwipeView,虽然他将它用于 ImageView ,但我正在努力用布局替换它。 目前,如果我用 TextView 替换 ImageView 就可以了,但是我如
我正在使用 Swipeview ( http://cubiq.org/swipeview ) 创建可在 iPhone 和 Android 上运行的触控式 carousel。基础知识非常有用。 当我尝试
我必须在 SwipeView 中使用 QML 组件(例如项目 1、项目 2、项目 3)而不使用 Repeater 来实现页面,并且还需要实现翻页器,如下所示。 getPreviousPage Rect
我正在尝试制作一个带有按钮的滑动 View ,只要单击该按钮,它就会打开第二个 Activity ,但我无法在点击监听器中设置 setActivity 这是我的代码。将进行哪些更改我在我的寻呼机适配器
我的新项目由一个带有 6 个 fragment 的抽屉导航组成(奥迪/宝马/起亚...汽车品牌)。我希望每个 fragment 都有 2 个其他 fragment ( Models ,其中将有一个带有
我是 android 的新手。我正在做简单的 aphabate 应用程序。在那个应用程序中我正在使用字母表字母。当在字母上滑动时它将如何移动到下一个字母。请给我建议 提前致谢 最佳答案 我想建议您查看
我正在使用 iScroll4 在移动网站中的图像上创建水平滚动效果。 iScroll 工作得很好,但问题是 iScroll 包装器中包含的图像禁用了 native 垂直滚动。换句话说,在 iScrol
可能这是一个骗局,但我一直在寻找解决方案,它们总是与我的问题略有不同。 所以:我目前正在创建一个应用程序,其中包含 2 个可滑动的 fragment 。 TaskGroupFragment 显示一个列
我正在努力避免 SideView 和 ListView 似乎都喜欢的这种烦人的重叠。这是一个演示问题的示例: 注意:当您滑动 SwipeView 时请查看左侧的绿色矩形,当您向下滚动 ListView
我使用 swipeview 在两个页面之间滑动,每个页面本身就是一个 Activity (一个 xml 和一个 java 文件)。如果没有 swipeview,我的应用程序可以正常工作,并且我的数据库
我是一名优秀的程序员,十分优秀!