Reply
Thread Tools
Posts: 650 | Thanked: 619 times | Joined on Nov 2009
#1
I would like to use the ContextMenu to perform deletion of a list item through RemorseItem.

I followed the example on the reference, declared the contextmenu as a component and instantiated it within the list delegate. The problem I have now is, I cannot access the item's property (e.g. I want to invoke the RemorseItem) within the ContextMenu. One thing I tried was to connect the 'activated' signal from ContextMenu to a function for executing the RemorseItem within the delegate. But the function always got triggered when the ContextMenu was instantiated, not when the delete entry was pressed.

The codes look like this:
Code:
    
Component {
        id: posEditDelegate
        BackgroundItem {
                .......
     
                // Invoke contextMenu
                onPressAndHold: {
                    ...
                    if (!posEditListView.contextMenu)
                        posEditListView.contextMenu = contextMenuComp.createObject(posEditListView);
                    // TODO: hook up context menu to delegate item...
                    posEditListView.contextMenu.activated.connect(remorseDeleteAction());

                    posEditListView.contextMenu.show(myListItem);

                }

                RemorseItem {
                    id: remorse
                }

                function remorseDeleteAction() {
                    remorse.execute(...)
                }
        }
}

Component {
        id: contextMenuComp

        ContextMenu {
            MenuItem { text: qsTr("Delete"); onClicked: { } }

            onActivated: {
                console.log("On activated")
            }
        }
    }
Can anyone tell me how to get this working? Thanks in advance.

Last edited by sony123; 2013-07-09 at 16:14.
 

The Following 2 Users Say Thank You to sony123 For This Useful Post:
Posts: 650 | Thanked: 619 times | Joined on Nov 2009
#2
My solution is to reference the currentItem of the listview then move the remorseDeleteAction to the root item of delegate:

Code:
        ContextMenu {
               MenuItem {
                text: qsTr("Delete");
                onClicked: {
                    posEditListView.currentItem.remorseDeleteAction();
                }
            }
        }
 

The Following User Says Thank You to sony123 For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 11:57.