PDA

View Full Version : Add a dropdown menu to QListWidgetItem



plan_rich
6th September 2010, 14:47
I'm having some problems adding a dropdown menu to my dynamically generated QListWidgetItem.

I subclass QListWidgetItem to my custom entry and generate my content in the subclass and finally add it to the QListWidget.

Now i want to add a dropdown menu to every QListWidgetItem to delete the entry or modify it!

I did some other gui programming (swing,gtk+) but it seems to be different to in qt?

Can somebody help me?

tbscope
7th September 2010, 06:00
What I probably would do, but this is just of the top of my head and without further checking:

If the items in the list all have the same context menu:
Create a slot that listens to the customContextMenuRequested signal of the widget.
Get the item at the given point, display the menu. Use either a signal mapper or clean up the connections before making new ones.

If the items can all have different actions, I would let each item handle its own actions.
Again from a slot connected to the customContextMenuRequested signal, create a new context menu based on the actions of the item at the given point.

onnyloh
7th September 2010, 16:17
QTableWidget is probably the class your are looking for.