【发布时间】:2014-01-11 18:17:58
【问题描述】:
我有一个带有主对话框的 GUI 应用程序,我向它添加了一个按钮。 按下按钮会添加另一个“对话框”,用户必须在其中输入一些值。 两个 Ui 文件都是用 QTDesigner 编写的,“对话框”有一个对象名为“tableCo”的“QtableWidget”我不知道为什么我不能更改这个 tableWidget 的属性:
from PyQt4 import QtGui, QtCore, Qt
from Main_Window import Ui_Dialog as Dlg
from dialog import Ui_MyDialog
class MainDialog(QtGui.QDialog, Dlg):
def __init__(self):
QtGui.QDialog.__init__(self)
self.setupUi(self)
self.connect(self.buttonOK,
QtCore.SIGNAL("clicked()"), self.onOK)
self.connect(self.buttonAbbrechen,
QtCore.SIGNAL("clicked()"), self.onClose)
self.connect(self.Button,
QtCore.SIGNAL("clicked()"), self.on_Button_clicked)
def on_Button_clicked(self, checked=None):
if checked==None: return
dialog = QtGui.QDialog()
dialog.ui = Ui_MyDialog()
dialog.ui.setupUi(dialog)
dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
dialog.exec_()
some_list=["A","B","C"]
#a list in another python class from another script that changes so
#the table properties have to be changed dynamically
#here I just take a simple list as an example
#the following two lines do not work (they work if tableCo is an
#object in the Main Dialog
self.tableCo.setColumnCount(len(some_list))
self.tableCo.setHorizontalHeaderLabels(some_list)
def onOK:
...
def onClose:
...
如果我按下按钮,我会看到我的“tableCo”小部件,但标题的属性没有改变,关闭此子对话框后,我收到以下错误消息
Traceback (most recent call last):
File "C:/gui.py", line 88, in on_Button_clicked
self.tableCo.setColumnCount(len(some_list))
AttributeError: 'MainDialog' object has no attribute 'tableCo'
要在子对话框中配置小部件,我必须在代码中进行哪些更改?
【问题讨论】:
-
您可以将包含
tableCo的代码粘贴到此处或codepad.org 或其他地方吗?
标签: python pyqt qt-designer