[PySide] QShortcut suppressed by parent widget?

OHUfx frank at ohufx.com
Wed Jul 13 01:32:31 CEST 2016


    
Thanks.  Got it all working with actions now. Much nicer that way indeed. Onto the next challenge... 
Cheers, Frank

___________________________Sent from geek toy

-------- Original message --------
From: Tibold Kandrai <kandraitibold at gmail.com> 
Date: 12/07/2016  7:49 pm  (GMT+12:00) 
To: 'Frank Rueter | OHUfx' <frank at ohufx.com> 
Cc: pyside at qt-project.org 
Subject: RE: [PySide] QShortcut suppressed by parent widget? 

Hey, Sorry forgot to mention to ambiguous shortcuts. :)Also note that actions added to the widgets will also show up in the widgets context menu.http://doc.qt.io/qt-4.8/qwidget.html#addAction In general, I prefer using action where ever it is possible. They are very well support all around and give me a nice separation from the visuals. Tibold KandraiSoftware Architect & Engineer From: Frank Rueter | OHUfx [mailto:frank at ohufx.com] 
Sent: Tuesday, 12 July, 2016 01:09
To: Tibold Kandrai <kandraitibold at gmail.com>
Cc: pyside at qt-project.org
Subject: Re: [PySide] QShortcut suppressed by parent widget? Ah, much nicer, thanks.
Though I am getting this at the moment:
    QAction::eventFilter: Ambiguous shortcut overload: I

Will investigate further.
Thanks Tibold.

frank

On 07/11/2016 07:42 PM, Tibold Kandrai wrote:Hey, You could use actions:https://gist.github.com/tibold/7451adb89c41c3718148168cee191ac3 Tibold KandraiSoftware Architect & Engineer From: PySide [mailto:pyside-bounces+kandraitibold=gmail.com at qt-project.org] On Behalf Of Frank Rueter | OHUfx
Sent: Monday, 11 July, 2016 09:17
To: Alexey Vihorev <vihorev at gmail.com>
Cc: pyside at qt-project.org
Subject: Re: [PySide] QShortcut suppressed by parent widget? Thanks, but it doesn't seem to make a difference.On 07/11/2016 07:13 PM, Alexey Vihorev wrote:self.shortcut = QtGui.QShortcut(self, context=QtCore.Qt.WidgetShortcut)The context. In your case IMO it should be QtCore.Qt.WindowShortcut. More here 2016-07-11 9:30 GMT+03:00 Frank Rueter | OHUfx <frank at ohufx.com>:Hi all,

below is some test code that shows the problem I'm having, where a shortcut assigned to a child widget will not be triggered once it's part of the main widget.
It works if the widget is called by itself but not when it's part of a parent widget.

I have been searching the internet for an solution but haven't had any luck.

Does anybody know what I'm doing wrong?

Cheers,
frank

import sys
from PySide import QtGui, QtCore


class MainWidget(QtGui.QWidget):
    
    def __init__(self, parent=None):
        super(MainWidget, self).__init__(parent)
        self.makeUI()
       
    def makeUI(self):
        self.layout = QtGui.QHBoxLayout()
        self.setLayout(self.layout)
        sw1 = SubWidget('test1')
        sw2 = SubWidget('test2')
        sw3 = SubWidget('test3')
        self.layout.addWidget(sw1)
        self.layout.addWidget(sw2)
        self.layout.addWidget(sw3)

class SubWidget(QtGui.QLabel):
    def __init__(self, text, parent=None):
        super(SubWidget, self).__init__(parent)
        self.setText(text)  
        self.shortcut = QtGui.QShortcut(self, context=QtCore.Qt.WidgetShortcut)
        self.shortcut.setKey('i')
        self.shortcut.activated.connect(self.showInfoWidget)

    def showInfoWidget(self, text):
        print 'showing info for', self.text()


if __name__ == '__main__':
    app = QtGui.QApplication([])
    w = MainWidget()
    w.show()
    sys.exit(app.exec_())



-- vfx compositing | workflow customisation and consulting 
_______________________________________________
PySide mailing list
PySide at qt-project.org
http://lists.qt-project.org/mailman/listinfo/pyside


-- Алексей Вихорев  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160713/7945dba3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 2666 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20160713/7945dba3/attachment.png>


More information about the PySide mailing list