PDA

View Full Version : [PYQT4] QToolButton problem with its state



trapanator
14th September 2010, 10:57
Hi,

i'm writing a PyQT program. I've set up a Qtoolbar with a QtoolButton, which shows a menu of 3 buttons with 3 different icons.

The problem is that the QToolButton shows *always* the icon of the first action (this happens if I click on the second and on third...).

If I click on second action, the "checkable" state of the button is visible on the menu, but the toolbutton shows still the first action, as you can see in this image:

5184



Can you tell me if this code is correct?


# ACTIONS

self.actionFirstBut = QAction(QIcon(":/plugins/FIRST.png"), \
"First button", self.iface.mainWindow())
self.actionFirstBut.setCheckable (True)
QObject.connect(self.actionFirstBut, SIGNAL("activated()"), self.runFirst)

[...]


# TOOLBAR

self.topToolbar = self.iface.addToolBar ( "test" )
self.topToolbar.setObjectName ("test")


# TOOLBUTTON

self.civiciToolButton = QToolButton()
self.civiciToolButton.setPopupMode( QToolButton.InstantPopup )
self.civiciToolButton.setAutoRaise( True )
self.civiciToolButton.setToolButtonStyle(Qt.ToolBu ttonIconOnly)
self.civiciToolButton.setCheckable( True )

self.civiciToolButton.addAction( self.actionFirstBut )
self.civiciToolButton.addAction( self.actionSecondBut )
self.civiciToolButton.addAction( self.actionThirdButton )

self.civiciToolButton.setDefaultAction( self.actionFirstBut )

self.topToolbar.addWidget( self.civiciToolButton )