[PyQt] QKeySequence vs standardKey

Juergen Urner jUrner at arcor.de
Thu Aug 16 12:11:30 BST 2007


Phil wrote:
> On Wednesday 15 August 2007 6:51 pm, Juergen Urner wrote:
> > Hello,
> >
> >
> > I'd like to report a bug suspect. No idea if it is related to PyQt or to Qt
> > and no idea how to give additional debug information.
> >
> > So, in a few words
> >
> >  >> QKeySequence(QKeySequence.Copy)
> >
> > reliably crashes one of my Guis. Looks like QKeySequence() for some
> > reason does
> > not like to be initialized with StandardKeys.
> >
> >
> > Qt 4.3.0
> > PyQt 4.3
>
> Works fine for me.
>
> Phil

At least on my machine (ubuntu feisty) I get arbitrary chars as text for 
accelerators
in the "bugs" menu. Something wrong with my code or can anyone confirm?

Jürgen


from PyQt4 import QtCore, QtGui


class W(QtGui.QMainWindow):
   
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
       
        mb = self.menuBar()
       
        standardKeys = (
            ('Cut', QtGui.QKeySequence.Cut),
            ('Copy', QtGui.QKeySequence.Copy),
            ('Paste', QtGui.QKeySequence.Paste),
        )
       
        m = QtGui.QMenu('noBugs', self)
        mb.addMenu(m)
        for text, standardKey in standardKeys:
            act = QtGui.QAction(text, self)
            act.setShortcut(standardKey)
            m.addAction(act)
       
        m = QtGui.QMenu('bugs', self)
        mb.addMenu(m)
        for text, standardKey in standardKeys:
            act = QtGui.QAction(text, self)
            act.setShortcut(QtGui.QKeySequence(standardKey))
            m.addAction(act)
           

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    w = W()
    w.show()
    res = app.exec_()
    sys.exit(res)










More information about the PyQt mailing list