Results 1 to 2 of 2

Thread: TableView, use of delegate to edit an item

  1. #1
    Join Date
    Jan 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default TableView, use of delegate to edit an item

    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 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: TableView, use of delegate to edit an item

    That looks already quite good.
    What you might want to do is move the MouseArea into the Label, so that it is also "invisible" when the label is.

    Instead of states it might be easier to just have a bool property in spinBoxDelegateItem1 and bind the spinbox and label visible properties to it, so that one is visble when the property is true and the other when it is not.

    Something like
    Qt Code:
    1. property bool showInput
    2.  
    3. SpinBox {
    4. visible: parent.showInput
    5. }
    6. Label {
    7. visible: !parent.showInput
    8. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

Similar Threads

  1. Tableview dialog as delegate
    By drmacro in forum Qt Programming
    Replies: 5
    Last Post: 28th October 2015, 07:45
  2. How to do QChartView delegate like QTableView item delegate
    By malleeswarareddy.s in forum Qt Programming
    Replies: 0
    Last Post: 16th September 2015, 11:37
  3. Edit Control on a TableView
    By Kyef in forum Newbie
    Replies: 1
    Last Post: 7th August 2015, 21:50
  4. Edit TableView Content
    By emorgen in forum Newbie
    Replies: 7
    Last Post: 2nd June 2010, 22:00
  5. TableView Delegate questions
    By No-Nonsense in forum Qt Programming
    Replies: 3
    Last Post: 11th December 2006, 09:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.