Hello,
I'am learning QML. I try to move a QT C++ application to a qml/C++ application. I write a tableview with for model a class derivated from QAbstractTableModel. The item are correctly show, no problem. I wan't to edit item : so when I click on a integer item, I want to show a SpinBox to change the value (I don't want to show the spinBox when I dont edit the Item). I try to find example, but found nothing.
If you can help me in my code or give me an exemple, thank in advance.
Qt Code:
  1. import QtQuick 2.4
  2. import QtQuick.Controls 1.2
  3. import QtQuick.Layouts 1.0
  4.  
  5. Item {
  6. id: item1
  7. width: 600
  8. height: 400
  9. Component {
  10. id : spinBoxDelegate1
  11. Item {
  12. id : spinBoxDelegateItem1
  13. SpinBox {
  14. id: spinBoxDelegateSpin1
  15. anchors.fill: parent
  16. value: styleData.value+1
  17. visible: false
  18. onEditingFinished: {
  19. onClicked: recipe.state = 'Standard';
  20. spinBoxDelegateLabel1.text=value;
  21. }
  22. }
  23. Label {
  24. id: spinBoxDelegateLabel1
  25. text: styleData.value
  26. }
  27. MouseArea {
  28. anchors.fill: parent
  29. propagateComposedEvents: true
  30. onDoubleClicked: {
  31. print("(onEntered) "+styleData.role)
  32. if (styleData.role=="item1") {
  33. spinBoxDelegateItem1.state = 'Details';
  34. }
  35. }
  36. }
  37. states: [
  38. State {
  39. name: "Details"
  40. PropertyChanges { target: spinBoxDelegateSpin1; visible: true }
  41. PropertyChanges { target: spinBoxDelegateLabel1; visible: false }
  42. },
  43. State {
  44. name: "Standard"
  45. PropertyChanges { target: spinBoxDelegateSpin1; visible: false }
  46. PropertyChanges { target: spinBoxDelegateLabel1; visible: true }
  47. }
  48. ]
  49. }
  50. }
  51. TableView {
  52. id: tableView0
  53. width: 500
  54. height: 200
  55. model: modelOption14at0
  56. TableViewColumn {
  57. title: "name"
  58. movable: false
  59. role: "item0"
  60. delegate:textInputDelegate
  61. }
  62. TableViewColumn {
  63. title: "integer"
  64. movable: false
  65. role: "item1"
  66. delegate:spinBoxDelegate1
  67. }
  68. anchors.left:parent.left
  69. anchors.leftMargin: 0
  70. anchors.bottom: parent.bottom
  71. anchors.bottomMargin: 0
  72. anchors.right: colon1.left
  73. anchors.rightMargin: 0
  74. anchors.top: parent.top
  75. anchors.topMargin: 0
  76. }
  77. }
To copy to clipboard, switch view to plain text mode