亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 QML 中的 TableView 從 QtQuickControls 1 獲取列數據?

如何使用 QML 中的 TableView 從 QtQuickControls 1 獲取列數據?

慕田峪4524236 2023-08-18 16:56:13
我正在使用import QtQuick.Controls 1.4 as CC. 每當我單擊第一列時,我得到的輸出是未定義的,而我能夠獲取其余列的數據。第一列有一個代表。從具有委托的第一列獲取數據的方法是什么?import QtQuick.Window 2.12import QtQuick 2.12import QtQuick.Controls 1.4 as CCimport QtQuick.Controls.Styles 1.4Window{    visible: true    width: 640    height: 480    title: qsTr("Hello World")    CC.TableView    {        height: 400; width: 600        style: TableViewStyle        {            headerDelegate: Rectangle            {                height: 20                color: "lightsteelblue"                Text                {                    width: parent.width                    text: styleData.value                }            }            rowDelegate: Rectangle            {                color: "blue"                height: 30                MouseArea                {                    id: ma                    anchors.fill: parent                    onClicked:                    {                        console.log(styleData.value)                    }                }            }            itemDelegate: Rectangle            {                color: "blue"                height: 30                Text                {                    text: styleData.value                }                MouseArea                {                    id: ma1                    anchors.fill: parent                    onClicked:                    {                        console.log(styleData.value)                    }                }            }        }
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

對于舊的(編輯過的)問題:您應該在控制臺日志行中

使用styleData.row而不是styleData.value


對于新問題:

您的列有一個委托,它會覆蓋表的項目委托。然后,當單擊第一列時,它實際上是調用控制臺日志的行的委托。


您可以通過將列委托更改為來解決此問題:


CC.TableViewColumn

{

    role: "aaa"

    title: "AAA"

    width: 100


    delegate: Item

    {

        Rectangle

        {

            anchors.left: parent.left

            id: pic

            radius: 100

            height: 15; width: 15; color: "red"

        }


        Text

        {

            id: text_id

            anchors.left: pic.right

            anchors.leftMargin: 10

            text: styleData.value

        }

        MouseArea

        {

            id: ma2

            anchors.fill: parent

            onClicked: {


                console.log(text_id.text)

            }

        }

    }

}


查看完整回答
反對 回復 2023-08-18
  • 1 回答
  • 0 關注
  • 152 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號