Results 1 to 6 of 6

Thread: PyQt : Signal like this

  1. #1
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default PyQt : Signal like this

    I am creating <QAction> in a loop and adding it to menu.

    Qt Code:
    1. for fileName in fileNames:
    2. action = QtGui.QAction(QtGui.QIcon(iconFile), fileName, menu)
    3. menu.addAction(action)
    To copy to clipboard, switch view to plain text mode 

    I need to connect this action to a python function in such a way that I should get <text> of QAction <fileName> or instance of QAction object itself.

    For example If action name is required
    Qt Code:
    1. def contextMenuAction(self, actionName):
    2. print actionName
    To copy to clipboard, switch view to plain text mode 
    If action object is required
    Qt Code:
    1. def contextMenuAction(self, actionObject):
    2. myData = actionObject.data()
    To copy to clipboard, switch view to plain text mode 

    How do I setup action and slot? Logically it would be like this:
    Qt Code:
    1. self.connect(action, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("contextMenuAction(str)"), fileName)
    2. self.connect(action, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("contextMenuAction(object)"), action)
    To copy to clipboard, switch view to plain text mode 
    Prashant


    qt-sdk-win-opensource-2009.03.1.exe
    Python 2.6.3
    PyQt-Py2.6-gpl-4.6-1
    Win XP, 32 Bit

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt : Signal like this

    Take a look at QSignalMapper.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: PyQt : Signal like this

    QxColorPicker has been created by sub classing QtGui.QWidget.

    The old style connection method is working fine.
    Qt Code:
    1. // Connect picker->slider
    2. #QtCore.QObject().connect(self.qColorPicker, QtCore.SIGNAL("brightnessChanged(int)"),
    3. #self.qSlider, QtCore.SLOT("setValue(int)"))
    To copy to clipboard, switch view to plain text mode 

    The new style method is not working.
    Qt Code:
    1. self.qColorPicker.brightnessChanged.connect(self.qSlider.setValue)
    To copy to clipboard, switch view to plain text mode 

    I am getting an error saying:
    Qt Code:
    1. AttributeError: 'QxColorPicker' object has no attribute 'brightnessChanged'
    To copy to clipboard, switch view to plain text mode 

    In <QxColorPicker>, I am emitting <brightnessChanged> signal at two places like this:
    Qt Code:
    1. self.emit(QtCore.SIGNAL("brightnessChanged(int)", self.myColor.value()))
    To copy to clipboard, switch view to plain text mode 

    suggestions?
    Prashant


    qt-sdk-win-opensource-2009.03.1.exe
    Python 2.6.3
    PyQt-Py2.6-gpl-4.6-1
    Win XP, 32 Bit

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt : Signal like this

    But what do you want from us?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Posts
    49
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: PyQt : Signal like this

    What's wrong with my new style syntax? Why it's not working?
    Qt Code:
    1. self.qColorPicker.brightnessChanged.connect(self.qSlider.setValue)
    To copy to clipboard, switch view to plain text mode 
    Prashant


    qt-sdk-win-opensource-2009.03.1.exe
    Python 2.6.3
    PyQt-Py2.6-gpl-4.6-1
    Win XP, 32 Bit

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: PyQt : Signal like this

    Obviously the object has no such attribute.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Handling unixSignal in PyQt in a console app
    By null in forum Qt Programming
    Replies: 0
    Last Post: 26th January 2009, 23:59
  2. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  3. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  4. Replies: 2
    Last Post: 17th May 2006, 21:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.