Форма (form1_x.ui):
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form1</class>
<widget class="QDialog" name="Form1">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>340</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QLineEdit" name="lineEdit1">
<property name="geometry">
<rect>
<x>16</x>
<y>256</y>
<width>273</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QListWidget" name="listBox1">
<property name="geometry">
<rect>
<x>16</x>
<y>16</y>
<width>369</width>
<height>209</height>
</rect>
</property>
<item>
<property name="text">
<string>New Item 1</string>
</property>
</item>
<item>
<property name="text">
<string>New Item 2</string>
</property>
</item>
</widget>
<widget class="QPushButton" name="pushButton1">
<property name="geometry">
<rect>
<x>296</x>
<y>256</y>
<width>83</width>
<height>26</height>
</rect>
</property>
<property name="text">
<string>X</string>
</property>
</widget>
</widget>
<tabstops>
<tabstop>listBox1</tabstop>
<tabstop>lineEdit1</tabstop>
<tabstop>pushButton1</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>pushButton1</sender>
<signal>clicked()</signal>
<receiver>listBox1</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>333</x>
<y>270</y>
</hint>
<hint type="destinationlabel">
<x>295</x>
<y>191</y>
</hint>
</hints>
</connection>
<connection>
<sender>lineEdit1</sender>
<signal>returnPressed()</signal>
<receiver>Form1</receiver>
<slot>AddEntry()</slot>
<hints>
<hint type="sourcelabel">
<x>152</x>
<y>266</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>140</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>AddEntry()</slot>
</slots>
</ui>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
class TdlgMain(QDialog):
def __init__(self,parent=None):
QDialog.__init__(self,parent)
uic.loadUi('form1_x.ui',self)
self.print_count()
def AddEntry(self):
print 'AddEntry(%r)'%self.lineEdit1.text()
self.listBox1.addItem(self.lineEdit1.text()) # (1)
self.print_count()
self.setWindowTitle(str(self.listBox1.count()))
def print_count(self):
print 'Count: %r'%self.listBox1.count()
if __name__ =='__main__':
app=QApplication(sys.argv)
dlgMain=TdlgMain()
dlgMain.show()
sys.exit(app.exec_())
Всё это происходит на:
- Debian 5
- QtDesigner 4.5.1
- Qt 4.5.1
- Python 2.5.4
- python-qt4 4.4.4-6