[PyQt] How to get the QRect of a QMenuBar (QPopupMenu) item ?

David Boddie davidb at mcs.st-and.ac.uk
Thu Nov 18 19:18:08 EST 2004


Erwan Adam <erwan.adam at cea.fr> wrote in message news:<cnfm98$lrs$1 at ellebore.saclay.cea.fr>...

> I try to introduce tooltips in my application written
> in PyQt (more precisly, in the menubar of my application)
> but I can't find a way to get the QRect instance
> associated to a QMenuBar item (neither a QPopupMenu item)

You need to call the itemGeometry method on your QPopupMenu
object with the index of the menu item you want to examine.

Something like this should work for popup menus:

# popup is a QPopupMenu containing several items
rect = popup.itemGeometry(2) # for the third item in the menu

It may be a little more difficult to get this information out
of QMenuBar because it looks like PyQt can't access the
itemRect function when the menu bar is created by a C++
object, such as a QMainWindow.

> I need the QRect 'cause I followed the tooltip.py file
> given with pyqt to do the job with a re-implementation
> of "maybeTip( self, pos )".

Are you trying to implement tooltips on menu items?

You may find that regulars on the PyQt/PyKDE mailing list can give
you more detailed advice:

http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Good luck!

David



More information about the Python-list mailing list