找回密码
 立即注册
收起左侧

关于qml的小问题

3
回复
8038
查看
[复制链接]

尚未签到

来源: 2015-6-1 15:23:54 显示全部楼层 |阅读模式
7Qter豆
  1. Mytab.qml


  2. import QtQuick 2.2
  3. import QtQuick.Controls 1.1
  4. import QtQuick.Layouts 1.1
  5. import QtWebKit 3.0

  6. Rectangle{
  7.         id:tab
  8.         width:parent.width
  9.         height:parent.height
  10.        

  11.         TextArea {
  12.                 id: textArea
  13.                 text:""
  14.                 anchors.fill: parent
  15.                        
  16.         }

  17. }
复制代码
main.qml
  1. import QtQuick 2.2
  2. import QtQuick.Controls 1.1
  3. import QtQuick.Layouts 1.1

  4. ApplicationWindow{
  5.         visible:true
  6.         width:640
  7.         height:480
  8.         id:window
  9.         title:"editor"

  10.         Column{
  11.                

  12.                 Button{
  13.                         id:getInfo
  14.                         width:100
  15.                         height:100
  16.                         text:"getinfo"
  17.                         onClicked:{
  18.                         console.log(textArea.text)
  19.                         }
  20.                
  21.                 }


  22.                 Button{
  23.                     id:addTab
  24.                     width:100
  25.                     height:100
  26.                     text: "add tab"
  27.                     onClicked:{
  28.                         var c = Qt.createComponent("Mytab.qml");
  29.                         tabview.addTab("tab", c);
  30.                         var last = tabview.count-1;
  31.                         tabview.getTab(last).active = true;
  32.                        
  33.                         }
  34.                 }
  35.        
  36.        
  37.        

  38.        
  39.                 TabView{
  40.                         id:tabview
  41.                         //anchors.top: addTab.bottom
  42.                          visible: true
  43.                          
  44.                          Layout.fillHeight: true
  45.                          Layout.fillWidth: true
  46.                  }
  47.         }
  48.    
  49. }



复制代码
各位大神,我写了一个带选项卡的程序,我想在主窗口中获取选项卡中的内容,就是程序的getInfo button中获取选项卡中的text内容,怎样在main.qml中获取到Mytab.qml中的textArea ,请问我该怎么做呢?如果有完整的关于qml的多选项卡记事本的程序例子,那就更好了!


最佳答案

查看完整内容

在你的mytab.qml 里面这样写:其实关键只是alias当成一个指针来使用而已
回复

使用道具 举报

尚未签到

2015-6-1 15:23:55 显示全部楼层
在你的mytab.qml 里面这样写:
  1. Rectangle{
  2.    id: tab


  3.    property alias textArea: textArea
复制代码
其实关键只是alias当成一个指针来使用而已
回复

使用道具 举报

尚未签到

2015-6-2 12:52:47 显示全部楼层
Joey_Chan 发表于 2015-6-1 20:11
在你的mytab.qml 里面这样写:其实关键只是alias当成一个指针来使用而已

请问 如果我想在多选项卡之间实现复制粘贴内容,该怎么实现呢
回复

使用道具 举报

尚未签到

2015-6-2 14:29:53 显示全部楼层
Zonzely 发表于 2015-6-2 12:52
请问 如果我想在多选项卡之间实现复制粘贴内容,该怎么实现呢

键盘control x c v 是直接支持的,如果你需要界面支持的话,要自己获取鼠标右键的信号,然后自己弄一个右键菜单
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了