i new pyqt4. trying link button setitem in table. below have far.
from pyqt4 import qtcore, qtgui try: _fromutf8 = qtcore.qstring.fromutf8 except attributeerror: def _fromutf8(s): return s try: _encoding = qtgui.qapplication.unicodeutf8 def _translate(context, text, disambig): return qtgui.qapplication.translate(context, text, disambig, _encoding) except attributeerror: def _translate(context, text, disambig): return qtgui.qapplication.translate(context, text, disambig) class ui_form(object): def setupui(self, form): form.setobjectname(_fromutf8("form")) form.resize(400, 300) self.tablewidget = qtgui.qtablewidget(form) self.tablewidget.setgeometry(qtcore.qrect(0, 0, 256, 192)) self.tablewidget.setobjectname(_fromutf8("tablewidget")) self.tablewidget.setcolumncount(3) self.tablewidget.setrowcount(3) self.pushbutton = qtgui.qpushbutton(form) self.pushbutton.setgeometry(qtcore.qrect(90, 230, 75, 23)) self.pushbutton.setobjectname(_fromutf8("pushbutton")) qtcore.qobject.connect(self.pushbutton, qtcore.signal(_fromutf8("clicked()")), self.tablewidget.setitem(0,0,qtgui.qtablewidgetitem("test"))) self.retranslateui(form) qtcore.qmetaobject.connectslotsbyname(form) def retranslateui(self, form): form.setwindowtitle(_translate("form", "form", none)) self.pushbutton.settext(_translate("form", "clear", none)) if __name__ == "__main__": import sys app = qtgui.qapplication(sys.argv) form = qtgui.qwidget() ui = ui_form() ui.setupui(form) form.show() sys.exit(app.exec_()) i error pretty long ( below ). there better way link button desire results want.
traceback (most recent call last): file "c:\python27\lib\site-packages\pyqt4\test_scripts\ag_test.py", line 57, in <module> ui.setupui(form) file "c:\python27\lib\site-packages\pyqt4\test_scripts\ag_test.py", line 40, in setupui qtcore.qobject.connect(self.pushbutton, qtcore.signal(_fromutf8("clicked()")), self.tablewidget.setitem(0,0,qtgui.qtablewidgetitem("adam"))) typeerror: arguments did not match overloaded call: qobject.connect(qobject, signal(), qobject, slot(), qt.connectiontype=qt.autoconnection): argument 3 has unexpected type 'nonetype' qobject.connect(qobject, signal(), callable, qt.connectiontype=qt.autoconnection): argument 3 has unexpected type 'nonetype' qobject.connect(qobject, signal(), slot(), qt.connectiontype=qt.autoconnection): argument 2 has unexpected type 'str'
another solution:
def setupui(self, form): ... self.pushbutton.clicked.connect(self.settablewidgetitem) def settablewidgetitem(self): self.tablewidget.setitem(0,0,qtgui.qtablewidgetitem("test"))
Comments
Post a Comment