[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: KActions in context menus
From: Kurt Granroth <granroth () suse ! com>
Date: 2001-09-24 16:14:56
[Download RAW message or body]
On Sunday 23 September 2001 02:45 pm, Dmitry Samoyloff wrote:
> Tell me please, can I deal with KActions in the context menus
> somehow, or should I use old-style callbacks with IDs?
Yes, you can use KActions in context menus! It's not *quite* as easy as
normal menus, but it's not hard either.
1. Your XML file should look *something* like this. Note that your context
menu should be OUTSIDE of the MenuBar
<MenuBar>
<Menu>
blah blah blah normal menu
</Menu>
</MenuBar>
<Menu name="popupmenu">
<Title>Cool KPopupMenu Title</Title>
<Action name="some_context_action" />
</Menu>
2. Instantiate your actions like normal:
new KAction( i18n("My Context Action"), ...., "some_context_action" );
3. Get a handle on your popup menu:
void Blah::mousePressEvent(QMouseEvent* e)
{
if ( e->button() != RightButton )
return;
QWidget *widget( factory()->container( "popupmenu", this ) );
if ( !widget || !widget->inherits( "KPopupMenu" ) )
return;
KPopupMenu *menu( static_cast<KPopupMenu*>(widget) );
menu->popup( ... )
}
The important part of that last snippet was the 'factory()->container(..)'.
The name in the 'container' needs to be the name of your context menu as
defined in the XML file.
Hope that answered your question!
--
Kurt Granroth | http://www.granroth.org
KDE Developer/Evangelist | SuSE Labs Open Source Developer
granroth@kde.org | granroth@suse.com
KDE -- Conquer Your Desktop
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic