Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Change child windows element text or proporty
Qt 6.11 is out! See what's new in the release blog

Change child windows element text or proporty

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mehmetakM Offline
    mehmetakM Offline
    mehmetak
    wrote on last edited by
    #1

    hi i have two qml file . one of them main.qml and other file users.qml
    i can access users.title with command ornektext.text = userScreen.title
    but i cant access id:username text.
    how can change username id text ?

    @
    main.qml

    import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Layouts 1.0
    import QtQuick.Dialogs 1.0
    import "content"
    ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Adres Kayıt Ekranı")
    ChildWindow { id: window1 }
    Users { id:userScreen }
    menuBar: MenuBar {
    Menu {
    title: qsTr("Adress")
    MenuItem {
    text: qsTr("&Open")
    onTriggered: console.log("Open action triggered");
    }
    MenuItem {
    text: qsTr("Exit")
    onTriggered: Qt.quit();
    }
    }
    Menu {
    title: "More Stuff"
    MenuItem {
    text: "Do Nothing"
    onTriggered: window1.visible = !window1.visible
    }
    MenuItem {
    text: "Yeni bir pencere aç "
    onTriggered: {
    userScreen.visible = !userScreen.visible
    ornektext.text = userScreen.title
    }
    .....
    .....
    ...
    users.qml

    import QtQuick 2.2
    import QtQuick.Window 2.1
    import QtQuick.Controls 1.2
    Window {
    id:userScreen
    width: 400
    height: 400
    title: "Kullanıcı Ekranı"
    Rectangle {
    id:cerceve
    width: 400
    height: 62
    Text
    {
    id:username
    text:qsTr("Mehmet")
    }
    }
    }
    @

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi and Welcome,

      Create a property in users.qml, bind it to username's text and then access this property from main.qml.
      Also please keep indentation in code so that its easier for others to read.

      157

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        The scope of all "ids" in QML is local file. They are not visible outside a file. So you need to export your text as a property:
        @
        proerty string text: "something"
        // ...
        Text
        {
        id:username
        text: userScreen.text
        }

        // And to access it in main:
        userScreen.text
        @

        (Z(:^

        1 Reply Last reply
        0
        • mehmetakM Offline
          mehmetakM Offline
          mehmetak
          wrote on last edited by
          #4

          thx sierdzio , thx p3c0

          i solved problem.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved