更新 3:
这是新代码,试图按照你告诉我的去做,但没有结果......我开始认为我在程序的某个地方做了一些非常愚蠢的事情......有什么新想法吗?
程序.py:
# -*- coding: utf-8 -*-
#imports:
import os
import platform
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import newchilddlg
from newchilddlg import *
#version:
__version__ = "1.0.0"
#Lists:
am = []
courtdate = []
board_number = []
namesurname = []
fathersname = []
mothersname = []
birthday = []
placeofbirth = []
nationality = []
address = []
tel = []
job = []
praxis = []
dayofdoing = []
placeofdoing = []
children = [am, courtdate, board_number, namesurname, fathersname, mothersname, birthday, placeofbirth, nationality, address, tel, job, praxis, dayofdoing, placeofdoing]
#Main Window Class:
class MainWindow(QMainWindow):
#__init__ function:
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
#Window size:
self.resize(800,600)
self.centralwidget = QtGui.QWidget(self)
self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget)
#Table Widget:
self.tableWidget = QtGui.QTableWidget(self.centralwidget)
self.vBar = self.tableWidget.verticalScrollBar()
self._vBar_lastVal = self.vBar.value()
self.horizontalLayout.addWidget(self.tableWidget)
self.vBar.valueChanged.connect(self.scrollbarChanged)
self.tableWidget.setGridStyle(QtCore.Qt.SolidLine)
self.tableWidget.setRowCount(100)
self.tableWidget.setColumnCount(15)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(6, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(7, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(8, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(9, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(10, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(11, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(12, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(13, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(14, item)
self.tableWidget.horizontalHeader().setDefaultSectionSize(140)
self.tableWidget.horizontalHeader().setHighlightSections(True)
self.tableWidget.horizontalHeader().setStretchLastSection(False)
self.tableWidget.verticalHeader().setDefaultSectionSize(30)
self.tableWidget.verticalHeader().setStretchLastSection(False)
self.horizontalLayout.addWidget(self.tableWidget)
self.setCentralWidget(self.centralwidget)
#Window Title:
self.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.setSortingEnabled(False)
#Collumns'names:
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(QtGui.QApplication.translate("MainWindow", "Α.Μ.", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(QtGui.QApplication.translate("MainWindow", "Ημερομηνία Δικάσιμου", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(QtGui.QApplication.translate("MainWindow", "Αριθμός Πινακίου", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(QtGui.QApplication.translate("MainWindow", "Ονοματεπώνυμο", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(QtGui.QApplication.translate("MainWindow", "Όνομα Πατρός", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(QtGui.QApplication.translate("MainWindow", "Όνομα Μητρός", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(QtGui.QApplication.translate("MainWindow", "Ημερομηνία Γέννησης", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(7)
item.setText(QtGui.QApplication.translate("MainWindow", "Τόπος Γέννησης", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(8)
item.setText(QtGui.QApplication.translate("MainWindow", "Εθνικότητα", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(9)
item.setText(QtGui.QApplication.translate("MainWindow", "Διεύθυνση Κατοικίας", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(10)
item.setText(QtGui.QApplication.translate("MainWindow", "Τηλέφωνο", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(11)
item.setText(QtGui.QApplication.translate("MainWindow", "Επάγγελμα-Ιδιότητα", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(12)
item.setText(QtGui.QApplication.translate("MainWindow", "Πράξη", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(13)
item.setText(QtGui.QApplication.translate("MainWindow", "Ημερομηνία Τέλεσης", None, QtGui.QApplication.UnicodeUTF8))
item = self.tableWidget.horizontalHeaderItem(14)
item.setText(QtGui.QApplication.translate("MainWindow", "Τόπος Τέλεσης", None, QtGui.QApplication.UnicodeUTF8))
#menubar:
self.menubar = QtGui.QMenuBar(self)
self.menubar.setEnabled(True)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menuFile = self.menubar.addMenu("&File")
self.menuFile.setSizeIncrement(QtCore.QSize(0, 0))
self.menuEdit = self.menubar.addMenu("&Edit")
self.setMenuBar(self.menubar)
self.menuFile.setTitle(QtGui.QApplication.translate("MainWindow", "File", None, QtGui.QApplication.UnicodeUTF8))
self.menuEdit.setTitle(QtGui.QApplication.translate("MainWindow", "Edit", None, QtGui.QApplication.UnicodeUTF8))
#Creating Action filenewchild:
self.filenewchild = self.createAction("&Εισαγωγή Ανηλίκου", self.doupdate, "Ctrl+C", "" ,"Εισαγωγή Δεδομέων Ανηλίκου")
self.menuFile.addAction(self.filenewchild)
self.filenewchild.setText(QtGui.QApplication.translate("MainWindow", "Εισαγωγή Ανηλίκου", None, QtGui.QApplication.UnicodeUTF8))
#Adding objects from lists to the Table Widget:
r=0
c=0
for x in children:
for i in x:
newItem = QtGui.QTableWidgetItem(i)
self.tableWidget.setItem(r, c, newItem)
r += 1
r = 0
c += 1
# Growing rows while scrolling down....
def scrollbarChanged(self, val):
bar = self.vBar
minVal, maxVal = bar.minimum(), bar.maximum()
avg = (minVal+maxVal)/2
rowCount = self.tableWidget.rowCount()
if val > self._vBar_lastVal and val >= avg:
self.tableWidget.insertRow(rowCount)
elif val < self._vBar_lastVal:
lastRow = rowCount-30
empty = True
for col in xrange(self.tableWidget.columnCount()):
item = self.tableWidget.item(lastRow, col)
if item and item.text():
empty=False
break
if empty:
self.tableWidget.removeRow(lastRow)
self._vBar_lastVal = val
#A function to help us create Actions faster:
def createAction(self,text, slot=None, shortcut=None, icon=None,
tip=None, checkable=False, signal="triggered()"):
action = QAction(text, self)
if icon is not None:
action.setIcon(QIcon(":/%s.png" % icon))
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
if slot is not None:
self.connect(action, SIGNAL(signal), slot)
if checkable:
action.setCheckable(True)
return action
#A function that updates the table:
def updatetable(self):
self.tableWidget.clear()
r=0
c=0
for x in children:
for i in x:
newItem = QtGui.QTableWidgetItem(i)
self.tableWidget.setItem(r, c, newItem)
r += 1
r = 0
c += 1
#Handles NewChildDlg actions:
def doupdate(self):
newchilddlg.main()
d = NewChildDlg(self)
if d.accept():
text = NewChildDlg.text()
am.append(text)
self.updatetable()
#Main loop:
if __name__ == '__main__':
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
newchilddlg.py:
# -*- coding: utf-8 -*-
#imports:
from PyQt4 import QtCore, QtGui
import sys
from PyKDE4.kdeui import KDateComboBox
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import program
from program import *
#NewChildDialog Class:
class NewChildDlg(QDialog):
#__init__ function:
def __init__(self, parent=None):
super(NewChildDlg, self).__init__(parent)
self.resize(400, 600)
self.lineEdit = QtGui.QLineEdit(self)
self.lineEdit.setGeometry(QtCore.QRect(160, 20, 211, 23))
self.lineEdit.editingFinished.connect(self.amlist)
self.kdatecombobox = KDateComboBox(self)
self.kdatecombobox.setGeometry(QtCore.QRect(160, 50, 211, 23))
self.lineEdit2 = QtGui.QLineEdit(self)
self.lineEdit2.setGeometry(QtCore.QRect(160, 80, 211, 23))
self.lineEdit3 = QtGui.QLineEdit(self)
self.lineEdit3.setGeometry(QtCore.QRect(160, 110, 211, 23))
self.lineEdit4 = QtGui.QLineEdit(self)
self.lineEdit4.setGeometry(QtCore.QRect(160, 140, 211, 23))
self.lineEdit5 = QtGui.QLineEdit(self)
self.lineEdit5.setGeometry(QtCore.QRect(160, 170, 211, 23))
self.kdatecombobox2 = KDateComboBox(self)
self.kdatecombobox2.setGeometry(QtCore.QRect(160, 200, 211, 23))
self.lineEdit6 = QtGui.QLineEdit(self)
self.lineEdit6.setGeometry(QtCore.QRect(160, 230, 211, 23))
self.lineEdit7 = QtGui.QLineEdit(self)
self.lineEdit7.setGeometry(QtCore.QRect(160, 260, 211, 23))
self.lineEdit8 = QtGui.QLineEdit(self)
self.lineEdit8.setGeometry(QtCore.QRect(160, 290, 211, 23))
self.lineEdit9 = QtGui.QLineEdit(self)
self.lineEdit9.setGeometry(QtCore.QRect(160, 320, 211, 23))
self.lineEdit10 = QtGui.QLineEdit(self)
self.lineEdit10.setGeometry(QtCore.QRect(160, 350, 211, 23))
self.lineEdit11 = QtGui.QLineEdit(self)
self.lineEdit11.setGeometry(QtCore.QRect(160, 380, 211, 23))
self.kdatecombobox3 = KDateComboBox(self)
self.kdatecombobox3.setGeometry(QtCore.QRect(160, 410, 211, 23))
self.lineEdit12 = QtGui.QLineEdit(self)
self.lineEdit12.setGeometry(QtCore.QRect(160, 440, 211, 23))
self.pushButton = QtGui.QPushButton(self)
self.pushButton.setGeometry(QtCore.QRect(90, 530, 211, 40))
self.pushButton.clicked.connect(self.addtolists)
self.label = QtGui.QLabel(self)
self.label.setGeometry(QtCore.QRect(20, 20, 211, 23))
self.label2 = QtGui.QLabel(self)
self.label2.setGeometry(QtCore.QRect(20, 50, 211, 23))
self.label3 = QtGui.QLabel(self)
self.label3.setGeometry(QtCore.QRect(20, 80, 211, 23))
self.label4 = QtGui.QLabel(self)
self.label4.setGeometry(QtCore.QRect(20, 110, 211, 23))
self.label5 = QtGui.QLabel(self)
self.label5.setGeometry(QtCore.QRect(20, 140, 211, 23))
self.label6 = QtGui.QLabel(self)
self.label6.setGeometry(QtCore.QRect(20, 170, 211, 23))
self.label7 = QtGui.QLabel(self)
self.label7.setGeometry(QtCore.QRect(20, 200, 211, 23))
self.label8 = QtGui.QLabel(self)
self.label8.setGeometry(QtCore.QRect(20, 230, 211, 23))
self.label9 = QtGui.QLabel(self)
self.label9.setGeometry(QtCore.QRect(20, 260, 211, 23))
self.label10 = QtGui.QLabel(self)
self.label10.setGeometry(QtCore.QRect(20, 290, 211, 23))
self.label11 = QtGui.QLabel(self)
self.label11.setGeometry(QtCore.QRect(20, 320, 211, 23))
self.label12 = QtGui.QLabel(self)
self.label12.setGeometry(QtCore.QRect(20, 350, 211, 23))
self.label13 = QtGui.QLabel(self)
self.label13.setGeometry(QtCore.QRect(20, 380, 211, 23))
self.label14 = QtGui.QLabel(self)
self.label14.setGeometry(QtCore.QRect(20, 410, 211, 23))
self.label15 = QtGui.QLabel(self)
self.label15.setGeometry(QtCore.QRect(20, 440, 211, 23))
self.setWindowTitle(QtGui.QApplication.translate("Form", "Εισαγωγή Ανηλίκου", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "Α.Μ.:", None, QtGui.QApplication.UnicodeUTF8))
self.label2.setText(QtGui.QApplication.translate("Form", "Ημερομηνία Δικασίμου:", None, QtGui.QApplication.UnicodeUTF8))
self.label3.setText(QtGui.QApplication.translate("Form", "Αριθμός Πινακίου:", None, QtGui.QApplication.UnicodeUTF8))
self.label4.setText(QtGui.QApplication.translate("Form", "Ονοματεπώνυμο:", None, QtGui.QApplication.UnicodeUTF8))
self.label5.setText(QtGui.QApplication.translate("Form", "Όνομα Πατρός:", None, QtGui.QApplication.UnicodeUTF8))
self.label6.setText(QtGui.QApplication.translate("Form", "Όνομα Μητρός:", None, QtGui.QApplication.UnicodeUTF8))
self.label7.setText(QtGui.QApplication.translate("Form", "Ημερομηνία Γέννησης:", None, QtGui.QApplication.UnicodeUTF8))
self.label8.setText(QtGui.QApplication.translate("Form", "Τόπος Γέννησης:", None, QtGui.QApplication.UnicodeUTF8))
self.label9.setText(QtGui.QApplication.translate("Form", "Εθνικότητα:", None, QtGui.QApplication.UnicodeUTF8))
self.label10.setText(QtGui.QApplication.translate("Form", "Διεύθυνση Κατοικίας:", None, QtGui.QApplication.UnicodeUTF8))
self.label11.setText(QtGui.QApplication.translate("Form", "Τηλέφωνο:", None, QtGui.QApplication.UnicodeUTF8))
self.label12.setText(QtGui.QApplication.translate("Form", "Επάγγελμα-Ιδιότητα:", None, QtGui.QApplication.UnicodeUTF8))
self.label13.setText(QtGui.QApplication.translate("Form", "Πράξη:", None, QtGui.QApplication.UnicodeUTF8))
self.label14.setText(QtGui.QApplication.translate("Form", "Ημερομηνία Τέλεσης:", None, QtGui.QApplication.UnicodeUTF8))
self.label15.setText(QtGui.QApplication.translate("Form", "Τόπος Τέλεσης:", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("Form", "Εισαγωγή", None, QtGui.QApplication.UnicodeUTF8))
def amlist(self):
self.text = str(self.lineEdit.text())
def addtolists(self):
dialog.accept()
#Main loop:
def main():
global dialog
dialog = NewChildDlg()
dialog.show()
dialog.exec_()