Ran*_*y_O 4 application-development qml ubuntu-sdk ubuntu-touch
我有一个应用程序,我试图让标题中的工具栏工作。在文档中,我注意到一个名为的属性head
似乎创建并向标题工具栏添加项目。
this 和 the 和有toolbaritems
什么不一样?
此外,相关的,在尝试使用此 head 属性时,我收到错误:无法分配给不存在的属性“head”(类似于问题为什么我收到错误“无法分配给不存在的属性“head”?)
哪一种是正确(或更好)的方式?
谢谢
兰迪
小智 6
toolbaritems
已被弃用Ubuntu.Components 1.1
,因此强烈建议不要使用它。它是为了向后兼容而维护的,但现在将项目添加到标题工具栏的正确方法是使用head.actions
.
head.actions
和之间的主要区别在于toolbaritems
您不再需要添加ToolbarButton
项目然后设置它们的action
属性。您所需要的head.actions
只是指定一个操作列表,然后它们将根据Ubuntu Touch 模式自动显示。
显示如何使用head
属性的示例如下(来自官方文档):
import QtQuick 2.0
import Ubuntu.Components 1.1
MainView {
width: units.gu(48)
height: units.gu(60)
Page {
title: i18n.tr("Example page")
Label {
anchors.centerIn: parent
text: i18n.tr("Hello world!")
}
head.actions: [
Action {
iconName: "search"
text: i18n.tr("Search")
},
Action {
iconName: "contacts"
text: i18n.tr("Contacts")
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
还有一些其他有用的设置PageHead
(例如自定义Item
显示而不是标题),所以我建议你看看这个页面。
如果您运行的是 Ubuntu 14.04 LTS,则这些新 API 不可用,因为它们依赖于 Qt 5.3。您可以按照此链接解决此问题。
归档时间: |
|
查看次数: |
352 次 |
最近记录: |