[PyQt] RuntimeError: no access to protected functions...

Andreas Pakulat apaku at gmx.de
Wed Jun 10 23:08:41 BST 2009

On 10.06.09 12:25:41, Victor Noagbodji wrote:
> hello, i'm getting the following error:
> RuntimeError: no access to protected functions or signals for objects
> not created from Python
> what i was trying to do is get the underlying lineEdit so i can set
> the position of my context menu.
> snippet:
> class DateEdit(QtGui.QDateEdit):
>   """Provides custom context menu"""
>   def __init__(self, parent=None):
>     super(DateEdit, self).__init__(parent)
>   def contextMenuEvent(self, event):
>     self.specialDatesMenu()
>   def specialDatesMenu(self):
>     menu = QtGui.QMenu('Special dates')
>     icon = Icon('tango/16x16/mimetypes/x-office-calendar.png').getQIcon()
>     menu.addAction(icon, 'today', self.setToday)
>     pos = self.lineEdit().cursorRect().center()       # runtime error here
>     menu.exec_(pos)
>   def setToday(self):
>     self.setDate(QtGui.QDate.currentDate())
> what am i doing wrong? thanks.

Isn't that pretty clear? You're trying to call a protected method from an
object that hasn't been created in Python (supposedly its been created in

Apart from that, why do you need the lineedit? The event that you get in
contextMenuEvent already provides you the location where the user clicked,
thats also were he expects the context menu to show up, so just use that.


Domestic happiness and faithful friends.

More information about the PyQt mailing list