简体   繁体   English

具有复制/剪切按钮的QML AppBar

[英]QML AppBar with Copy/Cut buttons

A typical android app containing text-fields adds copy/cat buttons to its AppBar for doing this actions. 一个典型的包含文本字段的android应用程序会在其AppBar中添加复制/猫按钮以执行此操作。 What is the best-practice way of doing this with QML? 使用QML的最佳做法是什么?

Should I write my own text-field widget that knows the app bar and tells it when to show the copy/cut buttons? 我应该编写自己的文本字段小部件来了解应用程序栏,并告诉它何时显示复制/剪切按钮吗? And how does the app bar know on which text-field it should perform the action? 应用栏如何知道应该在哪个文本字段上执行操作? Should the text-field somehow register itself as the active text-field? 文本字段是否应该以某种方式将自己注册为活动文本字段?

You can have a property TextField activeField : null put in your root window so it can be resolved from every child element, and on every TextField you can have a onActiveFocusChanged: activeField = activeFocus ? thisTextField : null 您可以在根窗口中放置一个property TextField activeField : null ,以便可以从每个子元素中解析该property TextField activeField : null ,并且在每个TextField上都可以具有onActiveFocusChanged: activeField = activeFocus ? thisTextField : null onActiveFocusChanged: activeField = activeFocus ? thisTextField : null . onActiveFocusChanged: activeField = activeFocus ? thisTextField : null

This way whatever text field is currently active will be assigned to activeField , so you can use that - if (activeField) activeField.paste() , you can set the copy/paste buttons to be enabled only when activeField != null . 这样,无论当前处于活动状态的文本字段都将分配给activeField ,因此可以使用if (activeField) activeField.paste() ,可以将复制/粘贴按钮设置为仅在activeField != null时启用。

As for the toolbar - if you use the QML ApplicationWindow it has a built in tool bar you can use directly, otherwise feel free to implement your custom one - it is quite easy. 至于工具栏-如果您使用QML ApplicationWindow它具有一个内置的工具栏,您可以直接使用它,否则可以随意实现您的自定义工具栏-这非常容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM