stephen76
28th July 2010, 18:26
Hi
I am trying to hook up a spin box to create rows in a table and automatically populate them with comboboxes .. I have manged to use the signal/slot mechanism to create the extra rows of the table (from the sigbnal of the spinbox) and the first row has the correct comboboxes (created on startup)- but I cannot figure out how to create and populate the new rows with new combo boxes.
The following is the code ...
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'table6.ui'
#
# Created: Tue Jul 27 16:31:53 2010
# by: PyQt4 UI code generator 4.7.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import functools
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(465, 531)
self.tableWidget = QtGui.QTableWidget(Form)
self.tableWidget.setGeometry(QtCore.QRect(20, 70, 351, 201))
self.tableWidget.setRowCount(1)
self.tableWidget.setColumnCount(3)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(1)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.comboBox = QtGui.QComboBox(Form)
self.comboBox.setGeometry(QtCore.QRect(30, 480, 61, 21))
self.comboBox.setMaxVisibleItems(2)
self.comboBox.setMaxCount(2)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtGui.QComboBox(Form)
self.comboBox_2.setGeometry(QtCore.QRect(150, 480, 121, 21))
self.comboBox_2.setMaxVisibleItems(2)
self.comboBox_2.setMaxCount(2)
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.tableWidget.setCellWidget(0,1,self.comboBox)
self.tableWidget.setCellWidget(0,2,self.comboBox_2 )
self.tableWidget.setColumnWidth(2,120)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(300, 20, 75, 25))
self.pushButton.setObjectName("pushButton")
self.spinBox = QtGui.QSpinBox(Form)
self.spinBox.setGeometry(QtCore.QRect(200, 20, 53, 22))
self.spinBox.setProperty("value", 1)
self.spinBox.setObjectName("spinBox")
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(20, 20, 141, 16))
self.label.setObjectName("label")
self.pushButton_2 = QtGui.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(20, 300, 91, 25))
self.pushButton_2.setObjectName("pushButton_2")
self.retranslateUi(Form)
self.comboBox.setCurrentIndex(0)
self.comboBox_2.setCurrentIndex(0)
QtCore.QObject.connect(self.spinBox, QtCore.SIGNAL("valueChanged(int)"), self.createMyRow)
#QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Add Passes", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(0).setText(Q tGui.QApplication.translate("Form", "Name", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(1).setText(Q tGui.QApplication.translate("Form", "Type", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(2).setText(Q tGui.QApplication.translate("Form", "Surface", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(0, QtGui.QApplication.translate("Form", "color", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(1, QtGui.QApplication.translate("Form", "bw", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(0, QtGui.QApplication.translate("Form", "closest surface", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(1, QtGui.QApplication.translate("Form", "opacity filtering", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.transla te("Form", "Passes", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "How many passes", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.trans late("Form", "Add Passes", None, QtGui.QApplication.UnicodeUTF8))
def createMyRow(self, rows):
howManyRows = self.tableWidget.rowCount()
diff = rows - howManyRows
if diff > 0:
start = howManyRows
while rows > start:
print(start)
self.tableWidget.insertRow(start)
self.comboBoxNew = QtGui.QComboBox(Form)
start = start +1
I am also running this to start the gui..
#!/usr/bin/python -d
import sys
from PyQt4 import QtCore, QtGui
from table8 import Ui_Form
# Lars set this path to where you have my scripts!
sys.path += ['/jobs/generic/shots/lightDome/qtDesigner']
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
#QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.ui.textEdit.clear )
#QtCore.QObject.connect(self.ui.lineEdit, QtCore.SIGNAL("returnPressed()"), self.add_entry)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
I guess
self.comboBoxNew = QtGui.QComboBox(Form)
in createMyRow(self, rows):
doesn't know about Form but I don' know how to get around this
Thanks in advance
stephen
I am trying to hook up a spin box to create rows in a table and automatically populate them with comboboxes .. I have manged to use the signal/slot mechanism to create the extra rows of the table (from the sigbnal of the spinbox) and the first row has the correct comboboxes (created on startup)- but I cannot figure out how to create and populate the new rows with new combo boxes.
The following is the code ...
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'table6.ui'
#
# Created: Tue Jul 27 16:31:53 2010
# by: PyQt4 UI code generator 4.7.3
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import functools
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(465, 531)
self.tableWidget = QtGui.QTableWidget(Form)
self.tableWidget.setGeometry(QtCore.QRect(20, 70, 351, 201))
self.tableWidget.setRowCount(1)
self.tableWidget.setColumnCount(3)
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(3)
self.tableWidget.setRowCount(1)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtGui.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
self.comboBox = QtGui.QComboBox(Form)
self.comboBox.setGeometry(QtCore.QRect(30, 480, 61, 21))
self.comboBox.setMaxVisibleItems(2)
self.comboBox.setMaxCount(2)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox_2 = QtGui.QComboBox(Form)
self.comboBox_2.setGeometry(QtCore.QRect(150, 480, 121, 21))
self.comboBox_2.setMaxVisibleItems(2)
self.comboBox_2.setMaxCount(2)
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.tableWidget.setCellWidget(0,1,self.comboBox)
self.tableWidget.setCellWidget(0,2,self.comboBox_2 )
self.tableWidget.setColumnWidth(2,120)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(300, 20, 75, 25))
self.pushButton.setObjectName("pushButton")
self.spinBox = QtGui.QSpinBox(Form)
self.spinBox.setGeometry(QtCore.QRect(200, 20, 53, 22))
self.spinBox.setProperty("value", 1)
self.spinBox.setObjectName("spinBox")
self.label = QtGui.QLabel(Form)
self.label.setGeometry(QtCore.QRect(20, 20, 141, 16))
self.label.setObjectName("label")
self.pushButton_2 = QtGui.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(20, 300, 91, 25))
self.pushButton_2.setObjectName("pushButton_2")
self.retranslateUi(Form)
self.comboBox.setCurrentIndex(0)
self.comboBox_2.setCurrentIndex(0)
QtCore.QObject.connect(self.spinBox, QtCore.SIGNAL("valueChanged(int)"), self.createMyRow)
#QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Add Passes", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(0).setText(Q tGui.QApplication.translate("Form", "Name", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(1).setText(Q tGui.QApplication.translate("Form", "Type", None, QtGui.QApplication.UnicodeUTF8))
self.tableWidget.horizontalHeaderItem(2).setText(Q tGui.QApplication.translate("Form", "Surface", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(0, QtGui.QApplication.translate("Form", "color", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox.setItemText(1, QtGui.QApplication.translate("Form", "bw", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(0, QtGui.QApplication.translate("Form", "closest surface", None, QtGui.QApplication.UnicodeUTF8))
self.comboBox_2.setItemText(1, QtGui.QApplication.translate("Form", "opacity filtering", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.transla te("Form", "Passes", None, QtGui.QApplication.UnicodeUTF8))
self.label.setText(QtGui.QApplication.translate("Form", "How many passes", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setText(QtGui.QApplication.trans late("Form", "Add Passes", None, QtGui.QApplication.UnicodeUTF8))
def createMyRow(self, rows):
howManyRows = self.tableWidget.rowCount()
diff = rows - howManyRows
if diff > 0:
start = howManyRows
while rows > start:
print(start)
self.tableWidget.insertRow(start)
self.comboBoxNew = QtGui.QComboBox(Form)
start = start +1
I am also running this to start the gui..
#!/usr/bin/python -d
import sys
from PyQt4 import QtCore, QtGui
from table8 import Ui_Form
# Lars set this path to where you have my scripts!
sys.path += ['/jobs/generic/shots/lightDome/qtDesigner']
class MyForm(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Form()
self.ui.setupUi(self)
#QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.ui.textEdit.clear )
#QtCore.QObject.connect(self.ui.lineEdit, QtCore.SIGNAL("returnPressed()"), self.add_entry)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyForm()
myapp.show()
sys.exit(app.exec_())
I guess
self.comboBoxNew = QtGui.QComboBox(Form)
in createMyRow(self, rows):
doesn't know about Form but I don' know how to get around this
Thanks in advance
stephen