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. QML reference by id. When works and when does not
Qt 6.11 is out! See what's new in the release blog

QML reference by id. When works and when does not

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.0k Views 2 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.
  • K Offline
    K Offline
    Kofr
    wrote on last edited by
    #1

    Hello, guys
    Following the two code examples. First shows working code and Second where we write style: comboBoxStyleId shows not working code. Why when referencing by element's id we get error?

    //first
    ComboBox {
            id: combo
            anchors.centerIn: parent
            width: 200
            model: [ "Banana", "Apple", "Coconut" ]
            style: ComboBoxStyle {
                id: comboBox
                background: Rectangle {
                    id: rectCategory
    
                    radius: 5
                    border.width: 2
                    color: "#fff"
                }
            }
    
    //second
    ComboBox {
            id: combo
            anchors.centerIn: parent
            width: 200
            model: [ "Banana", "Apple", "Coconut" ]
            style: comboBoxStyleId
    
            ComboBoxStyle {
                id: comboBoxStyleId
                background: Rectangle {
                    id: rectCategory
    
                    radius: 5
                    border.width: 2
                    color: "#fff"
                }
            }
    
    p3c0P 1 Reply Last reply
    0
    • K Kofr

      Hello, guys
      Following the two code examples. First shows working code and Second where we write style: comboBoxStyleId shows not working code. Why when referencing by element's id we get error?

      //first
      ComboBox {
              id: combo
              anchors.centerIn: parent
              width: 200
              model: [ "Banana", "Apple", "Coconut" ]
              style: ComboBoxStyle {
                  id: comboBox
                  background: Rectangle {
                      id: rectCategory
      
                      radius: 5
                      border.width: 2
                      color: "#fff"
                  }
              }
      
      //second
      ComboBox {
              id: combo
              anchors.centerIn: parent
              width: 200
              model: [ "Banana", "Apple", "Coconut" ]
              style: comboBoxStyleId
      
              ComboBoxStyle {
                  id: comboBoxStyleId
                  background: Rectangle {
                      id: rectCategory
      
                      radius: 5
                      border.width: 2
                      color: "#fff"
                  }
              }
      
      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @Kofr
      style requires a Component so you have to put ComboBoxStyle inside a Component and set its id to style.

      157

      K 1 Reply Last reply
      1
      • p3c0P p3c0

        Hi @Kofr
        style requires a Component so you have to put ComboBoxStyle inside a Component and set its id to style.

        K Offline
        K Offline
        Kofr
        wrote on last edited by
        #3

        @p3c0 thx, but I still do not understand why id reference to component does not work (

        p3c0P 1 Reply Last reply
        0
        • K Kofr

          @p3c0 thx, but I still do not understand why id reference to component does not work (

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @Kofr Since it requires Component and thus Component's id will work.

          157

          1 Reply Last reply
          1

          • Login

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