h_kassem
h_kassem

Reputation: 450

item inside component access

I have the following qml file:

import QtQuick 1.0
Component{

    Column{
        id: interHeader;

        Item{
         id:interItem
         height: 300
         width: 200

             Text{
                 id:title
                 text:"Text"
                 anchors.centerIn: parent
                 font.bold: true
                 elide:"ElideRight"
                 color: "Black"
             }
         }

        Item {
            width: parent.width
            height: 100

            //onClick event
            MouseArea {
                anchors.fill: parent

                onClicked:{
                        console.log("Ok");
                }
            }
        }
     }
}

The problem is that I need to assign some KeyNavigation to the interItem. I want to access the interItem from another qml file. How can this be done?

Upvotes: 5

Views: 2371

Answers (1)

Niraj D
Niraj D

Reputation: 66

There really is no benefit of using Component in a completely separate QML file. Remove Component and name your Qml file with a capital letter - e.g. InterHeader

Then define a property under your root item. For example:

import QtQuick 1.0
Item {
id: interHeader
property variant keyActionUp
Keys.onUpPressed: keyActionUp
}

OR

You can use the Connections function to execute callbacks for signals from interHeader.

http://doc.qt.nokia.com/4.7-snapshot/qml-connections.html

Upvotes: 2

Related Questions