QPopupMenu with dynamic adding/removing of toggled QActions possible?
Martin Baumgärtner <[email protected]> Sat, 15 Jan 2005 01:19:55 +0100
| Newsgroups | gmane.comp.mozilla.devel.qt |
|---|---|
| Organization | cmb |
| Message-ID | <[email protected]> |
Hi, as a newcomer to the Qt library I'd like to pour out the following question to the community: Can anybody help me with an appropriate technique in order to implement a QPopupMenu which can be dynamically grown/shrinked by adding/removing items of class QAction. It's important for me to use the toggle facility of the QAction class, because there seems to be no suitable alternative, e.g. to add menu items directly using the QPopupMenu::insertItem( ... ) functions. // ---------- CODE START ------------ ... QPopupMenu *popup_menu = new QPopupMenu( this ); QAction* new_item = new QAction( this, "new_item" ); new_item->setToggleAction( TRUE ); new_item->setOn( FALSE ); new_item->setText( "item_1" ); new_item->addTo( popup_menu ); ... // ------------ CODE END ------------ Using this concept I don't see any chance to get a valid (int) id that I can give to the new_item. And that would be what I'd need to use the QPopupMenu::removeItem( id ) for deleting items - or am I wrong? The inherited QPopupMenu::setItemChecked( int id, bool checked ) seems to be another idea, but I think this is not an easy solution for my problem, because then I need to manage some more signal/slot-connections in order to realize mouse/keyboard events. Is there a better technique for this task? Or do I have to manage a separate std::vector<QAction*> in order to use the QAction::removeFrom( QWidget *w ) for deletion? Thanks a lot in advance for any idea!!!! Martin