PyQt4 Windows - Toolbar Actions don't work. How can I fix them?
I have made a program that has a Toolbar with a few actions on it in Linux. The Toolbar and its actions work perfectly on a Linux OS, but when I run the code on a Windows machine, the actions just don't work. Everything looks the same as on Linux(yes I have PyQt4 installed on the Windows machine), even the toolbar, but when I click an item on the toolbar it just doesn't execute the given handler. I tried and made a basic PyQt4 program with a toolbar only to test if the bug is because of my program, but the results are the same. Here's the basic example program which doesn't work.
from PyQt4 import QtGui, QtCore
import sys
def aTest(obj = None):
print "If this appears, the action works."
app = QtGui.QApplication(sys.argv)
w = QtGui.QMainWindow()
toolBar = w.addToolBar("toolbar")
action = QtGui.QAction(QtGui.QIcon("path to icon here"), "testAction", w)
w.connect(action, QtCore.SIGNAL("activated()"), aTest)
toolBar.addAction(action)
w.show()
app.exec_()
This code works on Linux without a problem, but on Windows the actions just don't react when activated. Ignore the typos in the code.
开发者_如何学JAVAOS: Windows 7 Ultimate 32-bit (doesn't work on XP either)
Python version: Python 2.7
PyQt4 version: PyQt-Py2.7-x86-gpl-4.8.4-1
I hope someone out there can help me. I thank you all for your interest and help!
Have a nice day!
It's odd that it works in Linux, because I can only get it work on Windows by changing
w.connect(action, QtCore.SIGNAL("activated()"), aTest)
to
w.connect(action, QtCore.SIGNAL("triggered()"), aTest)
The QAction class reference only lists changed()
, hovered()
, toggled()
and triggered()
as valid signals. Unfortunately I don't have a Linux box handy to test things out further.
精彩评论