- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
更新:添加了SwipeView
的代码
我正在尝试自定义PageIndicator
以执行我目前拥有的三个按钮,即
通过单击PageIndicator
内的相应项来更改页面(当前我有3页,每页一个按钮,其中onClicked
设置为将SwipeView
更改为预定义索引-无需PageIndicator
)
显示每个页面指示符项的自定义图像(当前我有3页,每页带有一个自定义图像的按钮-没有PageIndicator
)
我的SwipeView
具有以下结构:
SwipeView {
id: detailsView
Layout.fillWidth: true
Layout.preferredHeight: layoutTopLevel.height * .9
Page {
id: captureViewPage
header: Text {
text: "Capture view"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
}
}
Page {
id: helpViewPage
header: Text {
text: "Help view"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
}
footer: TabBar {
id: helpViewSubCategories
currentIndex: 0
TabButton {
text: qsTr("Gestures")
}
TabButton {
text: qsTr("General")
}
}
}
Page {
id: settingsViewPage
header: Text {
text: "Settings view"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
}
footer: TabBar {
id: settingsViewSubCategories
currentIndex: 0
TabButton {
text: qsTr("Language")
}
TabButton {
text: qsTr("Device")
}
}
}
}
SwipeView
和
PageIndicator
(请参见下文)都是
ColumnLayout
的一部分,并且是子类:
ColumnLayout {
id: layoutDetailsAndMenu
spacing: 0
SwipeView { ... }
PageIndicator { ... }
}
delegate
的
PageIndicator
属性如何工作。例如以下QML代码
PageIndicator {
id: detailsViewIndicator
count: detailsView.count
currentIndex: detailsView.currentIndex
interactive: true
anchors.bottom: detailsView.bottom
anchors.bottomMargin: -40
anchors.horizontalCenter: parent.horizontalCenter
delegate: Rectangle {
implicitWidth: 15
implicitHeight: 15
radius: width
color: "#21be2b"
opacity: index === detailsView.currentIndex ? 0.95 : pressed ? 0.7 : 0.45
Behavior on opacity {
OpacityAnimator {
duration: 100
}
}
}
}
PageIndicator
内的相应项目可以更改页面
inactive
根本不起作用。我将引用文档说明此属性的作用:
delegate
进行自定义,也无法单击页面指示器项来更改当前页面(这些项的数量等于页面数,因此单击没有分配页面的索引是毫无疑问的)。
MouseArea
:
PageIndicator {
// ...
delegate: Rectangle {
MouseArea {
anchors.fill: parent
onClicked: {
if(index !== detailsView.currentIndex) {
detailsView.setCurrentIndex(index);
}
}
}
}
}
onClicked
事件处理程序(或任何此类调用),并检查
PageIndicator
的当前索引是否等于
SwipeView
中的页面。如果不是这种情况,我可以使用
setCurrentIndex(index)
将
SwipeView
设置为所选索引。
interactive
仍然困扰着我)。接下来是添加图像...
Qt
徽标。这是为了示范
QRC
URL为:
qrc:/icons/qtlogo.png
qrc:/icons/qtlogo1.png
qrc:/icons/qtlogo2.png
delegate: Image {
source: detailsViewIndicator.indicatorIcons[detailsView.currentIndex]
height: 30
width: 30
opacity: index === detailsView.currentIndex ? 0.95 : pressed ? 0.7 : 0.45
MouseArea {
anchors.fill: parent
onClicked: {
if(index !== detailsView.currentIndex) {
detailsView.setCurrentIndex(index);
source = detailsViewIndicator.indicatorIcons[detailsView.currentIndex];
}
}
}
}
indicatorIcons
是我的
variant
的
PageIndicator
属性:
property variant indicatorIcons: [
"qrc:/icons/qtlogo.png",
"qrc:/icons/qtlogo1.png",
"qrc:/icons/qtlogo2.png"
]
string
URL使用了
QRC
对象数组,因为似乎无法做到
delegate: detailsViewIndicator.indicatorImages[detailsView.currentIndex]
indicatorImages
被
property list<Image> indicatorImages: [
Image { source: "..." },
Image { source: "..." },
Image { source: "..." }
]
list
问题有关。用代码
delegate: Image {
source: detailsViewIndicator.indicatorIcons[detailsView.currentIndex]
// ...
}
0
,所以生成了带有
Image
的
source: "qrc:/icons/qtlogo.png"
,并且所有页面指示符项均已填充。如果我选择其他两个页面之一作为最初选择的页面,则分别得到
qrc:/icons/qtlogo1.png
和
qrc:/icons/qtlogo2.png
。
SwipeView
中滑动(不单击
PageIndicator
)会导致
qrc:/icons/qtlogo1.png
作为
Image
的源):
最佳答案
由于某种原因,非活动状态根本不起作用
我假设这是一个错字,因为使用interactive
属性对我有效(Qt 5.7):
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
PageIndicator {
count: 3
interactive: true
onCurrentIndexChanged: print(currentIndex)
}
}
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
PageIndicator {
id: detailsViewIndicator
count: 3
currentIndex: 0
interactive: true
delegate: Rectangle {
implicitWidth: 15
implicitHeight: 15
radius: width
color: "#21be2b"
opacity: index === detailsViewIndicator.currentIndex ? 0.95 : pressed ? 0.7 : 0.45
Behavior on opacity {
OpacityAnimator {
duration: 100
}
}
}
}
}
SwipeView
没有更改页面,则可能是问题所在,我们需要查看该代码。
source: detailsViewIndicator.indicatorIcons[detailsView.currentIndex]
source: detailsViewIndicator.indicatorIcons[index]
source: "qrc:/icons/qtlogo" + index + ".png"
SwipeView
并未将其
currentIndex
设置为
currentIndex
的
PageIndicator
。您可以这样做:
currentIndex: detailsViewIndicator.currentIndex
import QtQuick 2.5
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
ColumnLayout {
anchors.fill: parent
SwipeView {
id: detailsView
currentIndex: detailsViewIndicator.currentIndex
Layout.fillWidth: true
Layout.fillHeight: true
Page {
id: captureViewPage
header: Text {
text: "Capture view"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
}
}
Page {
id: helpViewPage
header: Text {
text: "Help view"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
}
footer: TabBar {
id: helpViewSubCategories
currentIndex: 0
TabButton {
text: qsTr("Gestures")
}
TabButton {
text: qsTr("General")
}
}
}
Page {
id: settingsViewPage
header: Text {
text: "Settings view"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 20
}
footer: TabBar {
id: settingsViewSubCategories
currentIndex: 0
TabButton {
text: qsTr("Language")
}
TabButton {
text: qsTr("Device")
}
}
}
}
PageIndicator {
id: detailsViewIndicator
count: detailsView.count
currentIndex: detailsView.currentIndex
interactive: true
anchors.horizontalCenter: parent.horizontalCenter
}
}
}
anchors.bottom
中使用垂直锚点(
anchors.top
,
ColumnLayout
)将不起作用。在垂直布局的直接子级中只能使用水平锚,反之亦然。
关于delegates - QML-自定义PageIndicator以为其指示的每个页面显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38520083/
我看了很多文章,但我仍然不清楚我们通常创建的普通委托(delegate)和多播委托(delegate)之间的区别。 public delegate void MyMethodHandler(objec
考虑以下几点: Action a1 = new Action(_insert); Action a2 = new Action(a1); a2 指的是什么?它是 a1,a1 的浅拷贝还是 a1 的深拷
我希望这听起来像是一个显而易见的问题,但是委托(delegate)返回类型是否也必须与其委托(delegate)的方法的返回类型相匹配? EG,像这样: public static void Save
我想使用 Kotlin 委托(delegate),但我不想在委托(delegate)人之外创建委托(delegate)。委托(delegate)的所有示例都如下所示: interface Worker
class SuperClass { var delegate : SuperClassDelegate? } protocol SuperClassDelegate { func d
我有一个加载 View 的 View ,需要将 View 推送到主导航 Controller 。 我已经为每个 View 设置了一个委托(delegate),并且基本上使我的调用沿着“链”返回到主导航
为简单起见,假设我想创建一个自定义 UITextField 并向其添加一个简单的行为;也就是说,如果文本字段成为第一响应者,背景颜色将变为绿色。 为此,在我的自定义类中,我必须将该类设置为委托(del
我非常有信心我应该能够使用非静态方法的委托(delegate),但下面给了我一个错误: public class TestClass { private delegate void TestD
在 C# 中不能从 System.Delegate 或 System.MulticastDelegate 继承。只要您声明标准的“运行时托管”方法,就完全可以在 MSIL 中执行此操作。但是,每次我向
我在 Storyboard 中定义了一个 iPad 界面,带有一个 SplitViewController。我想将 SplitViewController 的委托(delegate)设置为指向详细 C
我有几个解析器。有一个顶级的可以委托(delegate)给另一个。 Parser我们从 Reader 中获取他们的输入(可变)。我只想要一个 Parser为了能够一次解析,只有一个解析器应该有 Rea
一直以来我都在阅读关于反射的文章,每个人都在说:“反射很慢”,“反射很慢”。 现在我决定测试速度有多慢,令我惊讶的是,使用反射创建的委托(delegate)实际上是使用 lambda 创建的委托(de
在 Xcode 4.5 中启动了 Cocos2D 2.1 模板(没有物理引擎),针对 iOS 6 和 iPad。在 CDAudioManager.m 文件中,以下代码... AVAudioSessio
以下是来自未管理的 dll 的函数代码。它接受一个函数指针作为参数,并简单地返回被调用函数返回的值。 extern __declspec(dllexport) int _stdcall callDe
//NewCharts.h #import @interface NewCharts : UIViewController @property(nonatomic,retain)IBOutlet U
鉴于以下 MSDN 示例代码,为什么我不能定义 Action 委托(delegate)“内联”: public static void Main(string[] args) { Action
在虚幻引擎中,UFUNCTION用于通过附加说明符来丰富功能,以用于蓝图使用、复制和委托(delegate)。 然而,一些委托(delegate)类型似乎不允许绑定(bind) UFUNCTION(如
我刚刚将照片选择器放入我的项目中,一切正常。唯一的事情是它坚持在我设置委托(delegate)的地方给我以下警告 - Assigning to 'id' from incompatible type
我有一个 UIImageView 的子类,并且想将 self 作为参数传递给委托(delegate)。我在 MyImageView 之前收到错误“预期 ')'”。我需要将对象传递给委托(delegat
我正在开发 iOS 10 的语音转文本功能。 我希望调用 SFSpeechRecognitionTaskDelegate 的委托(delegate)方法来检查完成的结果。 func speechRec
我是一名优秀的程序员,十分优秀!