咨询下,tabview 下的 tab里KeyNavigation的用法。



  • 咨询下,tabview 下的 tab里KeyNavigation的用法。
    ![0_1482128260809_111.gif](正在上传 100%)
    官方的例子,用键盘上下键,选择一个控件的焦点·
    想在tabview 下用,单独的tab 里用 就不行了·

    import QtQuick 2.0
    import QtQuick.Controls 1.4
    
    TabView{
        id:meun_TabView;
        width:  300;
        height: 480;
        focus: true;
        activeFocusOnTab : true;
    
      Tab {
           id:aa;
           title: "111"	   	 
            Column {
        
                Rectangle {
                    id: topLeft
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
                    focus: true	;					
                    KeyNavigation.down: topRight
                    
                }
    
                Rectangle {
    
                    id: topRight
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"  
                    focus: true	;								
                    KeyNavigation.down: bottomLeft
    
                }				 
                Rectangle {
    
                    id: bottomLeft
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
                    focus: true	;	
                    KeyNavigation.down: bottomRight
    
                }
    
                Rectangle {
    
                    id: bottomRight
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
                    focus: true	;								
                    KeyNavigation.down:topLeft
    
                }
            }		
         }
        Tab {
               id:bb;
               title: "222"
        }
               
        Tab {
               id:cc;
               title: "333"
        }		   	   
    }
    


  • import QtQuick 2.0
    import QtQuick.Controls 1.4
    
    TabView{
        id:meun_TabView;
        width:  300;
        height: 480;
    
        activeFocusOnTab : true
    
        Tab {
            id:aa;
            title: "111"
    
            Column {
    
                Rectangle {
                    id: topLeft
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
                    focus: true
    
                    KeyNavigation.down: topRight
                    Keys.onPressed: {
                        console.log("press");
                    }
    
                    Component.onCompleted: {
                        // 这里可以强制topLeft 获取键盘焦点。
                        topLeft.forceActiveFocus();
                    }
    
                }
    
                Rectangle {
    
                    id: topRight
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
    
                    KeyNavigation.down: bottomLeft
    
                }
                Rectangle {
    
                    id: bottomLeft
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
    
                    KeyNavigation.down: bottomRight
    
                }
    
                Rectangle {
    
                    id: bottomRight
                    width: 50; height: 50
                    color: focus ? "red" :"lightgray"
    
                    KeyNavigation.down:topLeft
    
                }
            }
        }
        Tab {
            id:bb;
            title: "222"
        }
    
        Tab {
            id:cc;
            title: "333"
        }
    }
    


  • 谢谢了!可以了!


登录后回复
 

与 萌梦社区 的连接断开,我们正在尝试重连,请耐心等待