Hi all,

What's the best way to connect an action group triggered signal? The following isn't working:

self.connect(self.theActGroup, QtCore.SIGNAL("triggered(action)"), self.foo)

        

I'm adding a QToolButton with mutually exclusive actions to a QToolBar. I must be missing something obvious, since the method I connect to the triggered signal is not executing. eg:

        self.theButton          = QtGui.QToolButton()
        self.theButton.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
        self.theActGroup  = QtGui.QActionGroup(self.theButton)
        self.theActGroup.setExclusive(True)
        # actions added here...

self.connect(self.theActGroup, QtCore.SIGNAL("triggered(action)"), self.foo)
        # self.foo() not executed

See attached file for simple, working example.

Thanks!
Scott


#!/usr/bin/env python

import sys
from PyQt4 import QtCore, QtGui

class ActionGroupTest(QtGui.QDialog):
	def __init__(self, parent=None):
		QtGui.QDialog.__init__(self)

		self.tbar               = QtGui.QToolBar()
		self.tbar.setFloatable(False)
		self.tbar.setMovable(False)

		self.theButton          = QtGui.QToolButton()
		self.theButton.setText("The Menu Button")
		self.theButton.setPopupMode(QtGui.QToolButton.MenuButtonPopup)

		self.theActGroup  = QtGui.QActionGroup(self.theButton)
		self.theActGroup.setExclusive(True)
		self.setActionGroup()
		self.tbar.addWidget(self.theButton)
		
		self.formLayout         = QtGui.QVBoxLayout()
		self.formLayout.addWidget(self.tbar)
		self.setLayout(self.formLayout)

		self.connect(self.theActGroup, QtCore.SIGNAL("triggered(action)"), self.foo)
		


	def foo(action):
		print action.text()



	def setActionGroup(self):
		actOne     = QtGui.QAction("One", self.theButton)
		actOne.setCheckable(True)
		actOne.setChecked(False)
		self.theActGroup.addAction(actOne)
		self.theButton.addAction(actOne)

		actTwo     = QtGui.QAction("Two", self.theButton)
		actTwo.setCheckable(True)
		actTwo.setChecked(False)
		self.theActGroup.addAction(actTwo)
		self.theButton.addAction(actTwo)

		actThree   = QtGui.QAction("Three", self.theButton)
		actThree.setCheckable(True)
		actThree.setChecked(False)
		self.theActGroup.addAction(actThree)
		self.theButton.addAction(actThree)
		




class MainWindow(QtGui.QMainWindow):
	def __init__(self):
		QtGui.QMainWindow.__init__(self)

		self.displayDialog()

	def displayDialog(self):
		dialog = ActionGroupTest()
		self.connect(dialog, QtCore.SIGNAL("foo(string)"), self.printString)

		if dialog.exec_():
			print "dialog"




if __name__ == "__main__":
	app = QtGui.QApplication(sys.argv)
	mainwindow = MainWindow()
	mainwindow.show()
	sys.exit(app.exec_())

_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to