Hi,

I am facing several issues with a tableView that I am not able to solve. I hope there is someone here who can show me that what I need is the simplest thing.

What do I want to achieve?
For a GUI I want to have a table. The first column shall hold the title of the row. The second and third column shall have a spin box with custom max and min values. The fourth column shall hold the sum of the second and third column.

What do I have?
Qt Code:
  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Layouts 1.2
  4. import QtQuick.XmlListModel 2.0
  5.  
  6. Item {
  7. id: secondPage
  8. anchors.fill: parent
  9.  
  10. property int propValueSum: 96
  11. property int propValueCost: 480
  12.  
  13. ListModel {
  14. id: propertyModel
  15.  
  16. ListElement {
  17. name: qsTr("Curage")
  18. value: 12
  19. bonus: 0
  20. current: 12
  21. }
  22. ListElement {
  23. name: qsTr("Cunning")
  24. value: 12
  25. bonus: 0
  26. current: 12
  27. }
  28. }
  29.  
  30. TableView {
  31. id: propertyTable
  32. width: parent.width
  33. height: rowDelegate.height*9 // <- this is not working
  34.  
  35. model: propertyModel
  36.  
  37. TableViewColumn {
  38. role: "name"
  39. title: qsTr("Property")
  40. }
  41. TableViewColumn {
  42. role: "value"
  43. title: qsTr("Value")
  44.  
  45. delegate: SpinBox{
  46. id: propValue
  47. value: styleData.value
  48. minimumValue: 8
  49. maximumValue: secondPage.propValueSum > 99 ? propValue.value:14
  50. selectByMouse: false // <- this is not working still editable
  51.  
  52. property int lastValue: 12
  53.  
  54. onValueChanged: {
  55. var newValue = propValue.value + propertyModel.get(propertyTable.currentRow).bonus
  56. var delta = propValue.value - lastValue
  57. secondPage.propValueSum += delta
  58. lastValue = propValue.value
  59. propertyModel.setProperty(propertyTable.currentRow, "value", propValue.value)
  60. propertyModel.setProperty(propertyTable.currentRow, "current", newValue)
  61. }
  62. }
  63. }
  64. TableViewColumn {
  65. role: "bonus"
  66. title: qsTr("Bonus")
  67.  
  68. delegate: SpinBox{
  69. id: propBonus
  70. value: styleData.value
  71. selectByMouse: false
  72.  
  73. onValueChanged: {
  74. var newValue = propBonus.value + propertyModel.get(propertyTable.currentRow).value
  75. propertyModel.setProperty(propertyTable.currentRow, "bonus", propBonus.value)
  76. propertyModel.setProperty(propertyTable.currentRow, "current", newValue)
  77. }
  78. }
  79. }
  80. TableViewColumn {
  81. role: "current"
  82. title: qsTr("Actual")
  83. }
  84. rowDelegate: Rectangle{ // <- I needed to add this because the spinBox was larger than the row height.
  85. id: rowDelegate
  86. height: 25
  87. color: styleData.alternate? "#d9e5ea" : "white"
  88. }
  89. }
  90. }
To copy to clipboard, switch view to plain text mode 

What is missing?
  1. If I hover over a spinbox and use the mouse wheel the value of the active and the value of the "hovered" spinBox is changed. How can I prevent changes via mouse wheel?
  2. How can I set the table height to its content height?
  3. How can I dynamically adjust the row height to its content (in my case the spinBox)
  4. How can I adjust the width of the column to its content? I did not find an example explaining resizeColumnsToContents() in detail. Where do I have to put this?
  5. If I hardcode the width will I run into problems on different devices?


With this custom tableView I see a lot of warnings. Do I need to do anything about them?
Qt Code:
  1. qrc:/pages/SecondPage.qml:113: TypeError: Cannot read property 'bonus' of undefined // <- both int in my opinion and it works
  2. SpinBox_QMLTYPE_91_QML_98 QVariant(Invalid) QRect(0,0 0x0)
  3. SpinBox_QMLTYPE_91_QML_98 QVariant(Invalid) QRect(0,0 0x0)
To copy to clipboard, switch view to plain text mode 
And when I hover over the scrollbar
Qt Code:
  1. 2016-03-06 21:54:27.342 MyApp[4759:51929] inOptions: {
  2. "is.flipped" = 1;
  3. kCUIOrientationKey = kCUIOrientVertical;
  4. kCUIPartMaskKey = 768;
  5. kCUIThumbProportionKey = "0.665";
  6. state = normal;
  7. value = 0;
  8. widget = scrollbar;
  9. }
To copy to clipboard, switch view to plain text mode