1
votes

I have some questions regarding QML. I have a TableView and , when i click on a column header, i need to open a new window which contains all elements under that column with a button on the left of each element.
Clicking on that button should send a message back to TableView to update.
My questions are:

  • How can I catch the mouse click for a column?
  • Which would be best solution for the 2nd window: a tableview with 2 columns(one for the button and one for the element)? In this case I am not sure how to set the value for the 1st column...
  • How can i pass messages between 2 qml windows?From the 1st window i send the model(elements under the column) and from the 2nd windows i send back one or multiple values(depending on how many buttons are checked)

    Thank you
1

1 Answers

1
votes

You can communicate inbetween multiple windows in QML, just the the same way, as you communicate between any other two Items by referencing them via ids or assiging them to properties that you later use to reference them. An examople:

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0

Item {
    ApplicationWindow
    {
        id: appWindow
        width: 500
        height: 800
        visible: true

        ListModel {
            id: lm
            Component.onCompleted: {
                for (var i = 0; i < 42; i++) append( { message: 'Hellow World ' + i })
            }
        }

        ListView {
            id: lv
            width: 300
            height: 800
            model: lm
            delegate: Button {
                text: model.message
                onClicked: secondWindow.text = text
            }
        }
    }

    ApplicationWindow
    {
        id: secondWindow
        width: 500
        height: 800
        x: appWindow.x + 500
        y: appWindow.y
        visible: true
        property alias text: label.text

        Text {
            id: label
            anchors.centerIn: parent
        }
    }
}