【发布时间】:2019-06-07 16:58:40
【问题描述】:
我正在尝试处理对表格单元格的鼠标点击。只有当我单击某个单元格时,我才需要响应右键。但我找不到如何捕捉列号。使用来自 QtQuick 2.12 的 TableView。或者也许你可以不用列号? QtQuickControls中的Tableview我,由于各种原因,不能用。
TableView {
id: table
boundsBehavior: Flickable.StopAtBounds
anchors.fill: parent
columnSpacing: 0
rowSpacing: 0
anchors.rightMargin: 2
anchors.leftMargin: 5
anchors.bottomMargin: 5
anchors.topMargin: 70
clip: true
model: TableModel {
id: model
Component.onCompleted: {
model.init()
}
}
delegate: Rectangle {
id: tableDelegate
implicitWidth: textDelegate.implicitWidth + textDelegate.padding * 2
implicitHeight: 30
border.width: 0
TextField {
id: textDelegate
text: tabledata
anchors.fill: parent
anchors.verticalCenter: parent.verticalCenter
clip: true
horizontalAlignment: TextField.AlignHCenter
verticalAlignment: TextField.AlignVCenter
enabled: true
background: Rectangle {
border.color: "#e61d6887"
color: "#e6ffffff"
border.width: 1
}
selectByMouse: true
MouseArea {
id: mad
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: {
switch(mouse.button){
case Qt.RightButton:
console.log("right button")
dialog.open()
break
case Qt.LeftButton:
console.log("left button")
break
default:
break
}
}
}
}
}
}
【问题讨论】:
标签: qt qml tableview qt5 qtquick2