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. Access Tabview button from main
Forum Updated to NodeBB v4.3 + New Features

Access Tabview button from main

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 1.4k 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.
  • F Offline
    F Offline
    fermatqt
    wrote on last edited by
    #1

    hi!

    i have this form:

    Item {
        width: 900
        height: 900
        id: root
    
        TabView {
            id: tabView
            width: 900
            height: 900
    
            Tab {
                id: tabClienti
                title: "Clienti"
                source: "Clienti.qml"
    
                Rectangle {
                    id: rectangleClienti
                    x: 0
                    y: 32
                    width: 900
                    height: 69
                    color: "#ffffff"
    
                    TextField {
                        id: textNpu
                        x: 8
                        y: 22
                        width: 164
                        height: 26
                        placeholderText: qsTr("NPU")
                    }
    
                    Button {
                        id: btnClienti
                        x: 807
                        y: 21
                        text: qsTr("Cerca")
                    }
                }
            }
    }
    
    

    i'd need access to button from my main.qml:

    ApplicationWindow {
        visible: true
        width: 900
        height: 900
        minimumWidth: 900
        minimumHeight: 900
        maximumWidth: 900
        maximumHeight: 900
        title: qsTr("Cimoda Admin")
    
        menuBar: MenuBar {
            Menu {
                title: qsTr("File")
                MenuItem {
                    text: qsTr("&Open")
                    onTriggered: console.log("Open action triggered");
                }
                MenuItem {
                    text: qsTr("Exit")
                    shortcut: "Ctrl+Q"
                    onTriggered: Qt.quit();
                }
            }
        }
    
        MainForm {
            anchors.fill: parent
            // ACCESS TO BUTTON
        }
    }
    

    how can i do this operation in qml??

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Why do you need to access that button from your ApplicationWindow ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      F 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Why do you need to access that button from your ApplicationWindow ?

        F Offline
        F Offline
        fermatqt
        wrote on last edited by
        #3

        @SGaist

        hi!

        to set the onCliecked event.
        if i do simething like this:

                        Button {
                            id: btnClienti
                            x: 807
                            y: 21
                            text: qsTr("Cerca")
                            onClicked: messageDialog.show("hello")
                        }
        

        qtcreator tell me this message:

        Functions are not supported in a Qt Quick UI Form
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          It's not the role of your ApplicationWindow to know that there's a specific button in a sub-control from another control that you want do react on.

          You should rather emit a signal from that form that you will react on in ApplicationWindow. That way you'll avoid tight coupling and maintenance nightmare. Just imagine that you change that button for something else, now you have to modify at least two files to make things work again.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fermatqt
            wrote on last edited by
            #5

            something like this?

            Item {
                width: 900
                height: 900
                id: root
            
                signal searchClient(string msg)
            
                TabView {
                    id: tv
                    width: 900
                    height: 900
            
                    Tab {
                        id: tabClienti
                        title: "Clienti"
                        source: "Clienti.qml"
            
                        Rectangle {
                            id: rectangleClienti
                            x: 0
                            y: 32
                            width: 900
                            height: 69
                            color: "#ffffff"
            
                            TextField {
                                id: textNpu
                                x: 8
                                y: 22
                                width: 164
                                height: 26
                                placeholderText: qsTr("NPU")
                            }
            
                            Button {
                                id: btnClienti
                                x: 807
                                y: 21
                                text: qsTr("Cerca")
                                onClicked: root.searchClient("HELLO")
                            }
                        }
                    }
                }
            
            }
            

            but i have always this message:

            Functions are not supported in a Qt Quick UI Form
            

            and the designer doesn't work properly!

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fermatqt
              wrote on last edited by
              #6

              ok, this seems to work:

                      Button {
                          id: btnClienti
                          x: 800
                          y: 21
                          text: qsTr("Cerca")
                          onClicked: {
                              console.log('OK')
                          }
                      }
              
              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