[PyKDE] Problems with auto-connect and QAbstractButton.clicked()
Andreas Pakulat
apaku at gmx.de
Thu Jan 26 15:49:26 GMT 2006
Hi,
I have 2 problems with QAbstractButton.clicked and auto-connection:
1. the auto-connected slot gets called twice, I have no idea why
2. according to Qt4 docs clicked has a boolean argument which I cannot
use with the autoconnected slot.
The attached files include a minimal example.
Andreas
--
Your lucky number is 3552664958674928. Watch for it everywhere.
-------------- next part --------------
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Form</class>
<widget class="QWidget" name="Form" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>312</width>
<height>246</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QPushButton" name="pushButton" >
<property name="text" >
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>
-------------- next part --------------
import sys
import cStringIO
import os
from PyQt4 import QtCore, QtGui
# this time, we use the code generator
from PyQt4.uic import Compiler
def compileToType(filename):
code_string = cStringIO.StringIO()
widget_info = Compiler.compileUi(file(filename, "r"), code_string)
# the buffer code_string now contains the generated Python code
widget_module = compile(code_string.getvalue(), filename, "exec")
exec widget_module
return locals()[widget_info["uiclass"]]
class myWidget(QtGui.QWidget, compileToType("test.ui")):
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
# according to Qt4 docs clicked takes a boolean argument
def on_pushButton_clicked(self):
print "test"
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = myWidget()
w.show()
sys.exit(app.exec_())
More information about the PyQt
mailing list