QAction-related problems/needs

David Faure faure at kde.org
Wed Apr 5 19:23:05 BST 2006


On Wednesday 05 April 2006 01:30, Thiago Macieira wrote:
> David Faure wrote:
> >So this brings me to the following question: how do I add a widget to a
> > menu? This doesn't seem to be available; only actions can be added to a
> > menu. Hmm. Looking at qmenu.cpp ... it's worse than I thought. There
> > are no widgets at all used internally for every "item"; it's all done
> > by qstyle painting based on the action's text and icon :( Probably more
> > efficient, but very unflexible compared to Qt3's QPopupMenu.
> >Thiago: I remember a similar request on kde-devel, do you know if a TT
> > task ended up being created for that? Although now that I see the code
> > I see how this will never happen...
> 
> Isn't this what Hamish's patch (0119) is supposed to do? It associates an 
> action with a widget factory.

Yes but currently the widget factory only has a createToolBarWidget() method,
nothing about menu widgets - obviously, since menus don't support widgets yet.

> >Argl, is there really no better solution?
> >What used to be doable with one qlistbox subclass in qt3 would now
> > require 
> > - a kaction subclass 
> 
> I'd rather avoid this.

It actually makes sense in this case, to centralize code between the undo and redo actions;
e.g. to retrieve the actions to show in slotAboutToShow() and give them to the model;
can be done in the calling code but then it's duplicated.

> >- a qlistview subclass
> >- a qabstractlistmodel subclass
> 
> Doesn't QListWidget suffice for you? Do you really have to write your own 
> model?

It could be done with QListWidget, but I figured that writing two virtual methods
(rowCount and data) not much effort, when I see that QListWidget creates items
and a model over those items - much more code running and memory being used,
when I can just provide a model very simply. Wrappers around wrappers...
Anyway now that it's written I might as well use it, for the runtime gain, even though
I agree that for 10 actions the gain is not that much. But I think the number of lines
of code is the same with both solutions, so... :)

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).





More information about the kde-core-devel mailing list