将简单的 Qt Designer 表单加载到 Pyside
我在 Qt 设计器中创建了一个简单的表单,并尝试将其加载到我使用 PySide 创建的 Qt 应用程序中,但运气不佳。
这是从“pyside-uic”生成的代码:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'clientEditorForm.ui'
#
# Created: Tue Nov 3 23:46:41 2009
# by: PySide uic UI code generator
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_clientEditorForm(object):
def setupUi(self, clientEditorForm):
clientEditorForm.setObjectName("clientEditorForm")
clientEditorForm.resize(575, 446)
self.horizontalLayout_3 = QtGui.QHBoxLayout(clientEditorForm)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.splitter = QtGui.QSplitter(clientEditorForm)
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.layoutWidget = QtGui.QWidget(self.splitter)
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.searchLabel = QtGui.QLabel(self.layoutWidget)
self.searchLabel.setObjectName("searchLabel")
self.horizontalLayout_2.addWidget(self.searchLabel)
self.searchEdit = QtGui.QLineEdit(self.layoutWidget)
self.searchEdit.setObjectName("searchEdit")
self.horizontalLayout_2.addWidget(self.searchEdit)
self.clearButton = QtGui.QPushButton(self.layoutWidget)
self.clearButton.setObjectName("clearButton")
self.horizontalLayout_2.addWidget(self.clearButton)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.clientListView = QtGui.QListView(self.layoutWidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.clientListView.sizePolicy().hasHeightForWidth())
self.clientListView.setSizePolicy(sizePolicy)
self.clientListView.setObjectName("clientListView")
self.verticalLayout.addWidget(self.clientListView)
self.frame = QtGui.QFrame(self.splitter)
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout_3 = QtGui.QVBoxLayout(self.frame)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.formLayout = QtGui.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.nameEdit = QtGui.QLineEdit(self.frame)
self.nameEdit.setObjectName("nameEdit")
self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.nameEdit)
self.nameLabel = QtGui.QLabel(self.frame)
self.nameLabel.setObjectName("nameLabel")
self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.nameLabel)
self.profileButton = QtGui.QLabel(self.frame)
self.profileButton.setObjectName("profileButton")
self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.profileButton)
self.addressLabel = QtGui.QLabel(self.frame)
self.addressLabel.setObjectName("addressLabel")
self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.addressLabel)
self.locationLabel = QtGui.QLabel(self.frame)
self.locationLabel.setObjectName("locationLabel")
self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.locationLabel)
self.secureLabel = QtGui.QLabel(self.frame)
self.secureLabel.setObjectName("secureLabel")
self.formLayout.setWidget(4, QtGui.QFormLayout.LabelRole, self.secureLabel)
self.UUIDLabel = QtGui.QLabel(self.frame)
self.UUIDLabel.setObjectName("UUIDLabel")
self.formLayout.setWidget(5, QtGui.QFormLayout.LabelRole, self.UUIDLabel)
self.passwordLabel = QtGui.QLabel(self.frame)
self.passwordLabel.setObjectName("passwordLabel")
self.formLayout.setWidget(6, QtGui.QFormLayout.LabelRole, self.passwordLabel)
self.profileComboBox = QtGui.QComboBox(self.frame)
self.profileComboBox.setObjectName("profileComboBox")
self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.profileComboBox)
self.addressEdit = QtGui.QLineEdit(self.frame)
self.addressEdit.setObjectName("addressEdit")
self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.addressEdit)
self.locationComboBox = QtGui.QComboBox(self.frame)
self.locationComboBox.setObjectName("locationComboBox")
self.formLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.locationComboBox)
self.secureComboBox = QtGui.QComboBox(self.frame)
self.secureComboBox.setObjectName("secureComboBox")
self.formLayout.setWidget(4, QtGui.QFormLayout.FieldRole, self.secureComboBox)
self.UUIDEdit = QtGui.QLineEdit(self.frame)
self.UUIDEdit.setObjectName("UUIDEdit")
self.formLayout.setWidget(5, QtGui.QFormLayout.FieldRole, self.UUIDEdit)
self.passwordEdit = QtGui.QLineEdit(self.frame)
self.passwordEdit.setObjectName("passwordEdit")
self.formLayout.setWidget(6, QtGui.QFormLayout.FieldRole, self.passwordEdit)
self.verticalLayout_3.addLayout(self.formLayout)
self.aliasesGroupBox = QtGui.QGroupBox(self.frame)
self.aliasesGroupBox.setFlat(False)
self.aliasesGroupBox.setCheckable(False)
self.aliasesGroupBox.setObjectName("aliasesGroupBox")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.aliasesGroupBox)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.aliasesListView = QtGui.QListView(self.aliasesGroupBox)
self.aliasesListView.setObjectName("aliasesListView")
self.verticalLayout_2.addWidget(self.aliasesListView)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem)
self.addButton = QtGui.QPushButton(self.aliasesGroupBox)
self.addButton.setObjectName("addButton")
self.horizontalLayout_4.addWidget(self.addButton)
self.removeButton = QtGui.QPushButton(self.aliasesGroupBox)
self.removeButton.setObjectName("removeButton")
self.horizontalLayout_4.addWidget(self.removeButton)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.verticalLayout_3.addWidget(self.aliasesGroupBox)
spacerItem1 = QtGui.QSpacerItem(20, 38, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_3.addItem(spacerItem1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem2)
self.revertButton = QtGui.QPushButton(self.frame)
self.revertButton.setObjectName("revertButton")
self.horizontalLayout.addWidget(self.revertButton)
self.applyButton = QtGui.QPushButton(self.frame)
self.applyButton.setObjectName("applyButton")
self.horizontalLayout.addWidget(self.applyButton)
self.verticalLayout_3.addLayout(self.horizontalLayout)
self.horizontalLayout_3.addWidget(self.splitter)
self.searchLabel.setBuddy(self.searchEdit)
self.nameLabel.setBuddy(self.nameEdit)
self.profileButton.setBuddy(self.profileComboBox)
self.addressLabel.setBuddy(self.addressEdit)
self.locationLabel.setBuddy(self.locationComboBox)
self.secureLabel.setBuddy(self.secureComboBox)
self.UUIDLabel.setBuddy(self.UUIDEdit)
self.passwordLabel.setBuddy(self.passwordEdit)
self.retranslateUi(clientEditorForm)
QtCore.QMetaObject.connectSlotsByName(clientEditorForm)
def retranslateUi(self, clientEditorForm):
clientEditorForm.setWindowTitle(QtGui.QApplication.translate("clientEditorForm", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.searchLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Search", None, QtGui.QApplication.UnicodeUTF8))
self.clearButton.setText(QtGui.QApplication.translate("clientEditorForm", "Clear", None, QtGui.QApplication.UnicodeUTF8))
self.nameLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Name", None, QtGui.QApplication.UnicodeUTF8))
self.profileButton.setText(QtGui.QApplication.translate("clientEditorForm", "Profile", None, QtGui.QApplication.UnicodeUTF8))
self.addressLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Address", None, QtGui.QApplication.UnicodeUTF8))
self.locationLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Location", None, QtGui.QApplication.UnicodeUTF8))
self.secureLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Secure", None, QtGui.QApplication.UnicodeUTF8))
self.UUIDLabel.setText(QtGui.QApplication.translate("clientEditorForm", "UUID", None, QtGui.QApplication.UnicodeUTF8))
self.passwordLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Password", None, QtGui.QApplication.UnicodeUTF8))
self.aliasesGroupBox.setTitle(QtGui.QApplication.translate("clientEditorForm", "Aliases", None, QtGui.QApplication.UnicodeUTF8))
self.addButton.setText(QtGui.QApplication.translate("clientEditorForm", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.removeButton.setText(QtGui.QApplication.translate("clientEditorForm", "Remove", None, QtGui.QApplication.UnicodeUTF8))
self.revertButton.setText(QtGui.QApplication.translate("clientEditorForm", "Revert", None, QtGui.QApplication.UnicodeUTF8))
self.applyButton.setText(QtGui.QApplication.translate("clientEditorForm", "Apply", None, QtGui.QApplication.UnicodeUTF8))
然后是我的简单应用程序:
import sys
from PySide import QtCore, QtGui
from clientEditorForm import Ui_clientEditorForm
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.ui = Ui_clientEditorForm()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyMainWindow()
myapp.show()
sys.exit(app.exec_())
但是,当我尝试运行它时,我得到以下信息:
QLayout: Attempting to add QLayout "" to QMainWindow "clientEditorForm", which already has a layout
和分段错误。我正在遵循本教程中的基本说明,但是我不知道我做错了什么。
I create a simple form in Qt designer and am trying to load it in to a Qt application I'm creating with PySide but without much luck.
Here's the generated code from `pyside-uic':
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'clientEditorForm.ui'
#
# Created: Tue Nov 3 23:46:41 2009
# by: PySide uic UI code generator
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_clientEditorForm(object):
def setupUi(self, clientEditorForm):
clientEditorForm.setObjectName("clientEditorForm")
clientEditorForm.resize(575, 446)
self.horizontalLayout_3 = QtGui.QHBoxLayout(clientEditorForm)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.splitter = QtGui.QSplitter(clientEditorForm)
self.splitter.setOrientation(QtCore.Qt.Horizontal)
self.splitter.setObjectName("splitter")
self.layoutWidget = QtGui.QWidget(self.splitter)
self.layoutWidget.setObjectName("layoutWidget")
self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.searchLabel = QtGui.QLabel(self.layoutWidget)
self.searchLabel.setObjectName("searchLabel")
self.horizontalLayout_2.addWidget(self.searchLabel)
self.searchEdit = QtGui.QLineEdit(self.layoutWidget)
self.searchEdit.setObjectName("searchEdit")
self.horizontalLayout_2.addWidget(self.searchEdit)
self.clearButton = QtGui.QPushButton(self.layoutWidget)
self.clearButton.setObjectName("clearButton")
self.horizontalLayout_2.addWidget(self.clearButton)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.clientListView = QtGui.QListView(self.layoutWidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.clientListView.sizePolicy().hasHeightForWidth())
self.clientListView.setSizePolicy(sizePolicy)
self.clientListView.setObjectName("clientListView")
self.verticalLayout.addWidget(self.clientListView)
self.frame = QtGui.QFrame(self.splitter)
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout_3 = QtGui.QVBoxLayout(self.frame)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.formLayout = QtGui.QFormLayout()
self.formLayout.setObjectName("formLayout")
self.nameEdit = QtGui.QLineEdit(self.frame)
self.nameEdit.setObjectName("nameEdit")
self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.nameEdit)
self.nameLabel = QtGui.QLabel(self.frame)
self.nameLabel.setObjectName("nameLabel")
self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.nameLabel)
self.profileButton = QtGui.QLabel(self.frame)
self.profileButton.setObjectName("profileButton")
self.formLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.profileButton)
self.addressLabel = QtGui.QLabel(self.frame)
self.addressLabel.setObjectName("addressLabel")
self.formLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.addressLabel)
self.locationLabel = QtGui.QLabel(self.frame)
self.locationLabel.setObjectName("locationLabel")
self.formLayout.setWidget(3, QtGui.QFormLayout.LabelRole, self.locationLabel)
self.secureLabel = QtGui.QLabel(self.frame)
self.secureLabel.setObjectName("secureLabel")
self.formLayout.setWidget(4, QtGui.QFormLayout.LabelRole, self.secureLabel)
self.UUIDLabel = QtGui.QLabel(self.frame)
self.UUIDLabel.setObjectName("UUIDLabel")
self.formLayout.setWidget(5, QtGui.QFormLayout.LabelRole, self.UUIDLabel)
self.passwordLabel = QtGui.QLabel(self.frame)
self.passwordLabel.setObjectName("passwordLabel")
self.formLayout.setWidget(6, QtGui.QFormLayout.LabelRole, self.passwordLabel)
self.profileComboBox = QtGui.QComboBox(self.frame)
self.profileComboBox.setObjectName("profileComboBox")
self.formLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.profileComboBox)
self.addressEdit = QtGui.QLineEdit(self.frame)
self.addressEdit.setObjectName("addressEdit")
self.formLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.addressEdit)
self.locationComboBox = QtGui.QComboBox(self.frame)
self.locationComboBox.setObjectName("locationComboBox")
self.formLayout.setWidget(3, QtGui.QFormLayout.FieldRole, self.locationComboBox)
self.secureComboBox = QtGui.QComboBox(self.frame)
self.secureComboBox.setObjectName("secureComboBox")
self.formLayout.setWidget(4, QtGui.QFormLayout.FieldRole, self.secureComboBox)
self.UUIDEdit = QtGui.QLineEdit(self.frame)
self.UUIDEdit.setObjectName("UUIDEdit")
self.formLayout.setWidget(5, QtGui.QFormLayout.FieldRole, self.UUIDEdit)
self.passwordEdit = QtGui.QLineEdit(self.frame)
self.passwordEdit.setObjectName("passwordEdit")
self.formLayout.setWidget(6, QtGui.QFormLayout.FieldRole, self.passwordEdit)
self.verticalLayout_3.addLayout(self.formLayout)
self.aliasesGroupBox = QtGui.QGroupBox(self.frame)
self.aliasesGroupBox.setFlat(False)
self.aliasesGroupBox.setCheckable(False)
self.aliasesGroupBox.setObjectName("aliasesGroupBox")
self.verticalLayout_2 = QtGui.QVBoxLayout(self.aliasesGroupBox)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.aliasesListView = QtGui.QListView(self.aliasesGroupBox)
self.aliasesListView.setObjectName("aliasesListView")
self.verticalLayout_2.addWidget(self.aliasesListView)
self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_4.addItem(spacerItem)
self.addButton = QtGui.QPushButton(self.aliasesGroupBox)
self.addButton.setObjectName("addButton")
self.horizontalLayout_4.addWidget(self.addButton)
self.removeButton = QtGui.QPushButton(self.aliasesGroupBox)
self.removeButton.setObjectName("removeButton")
self.horizontalLayout_4.addWidget(self.removeButton)
self.verticalLayout_2.addLayout(self.horizontalLayout_4)
self.verticalLayout_3.addWidget(self.aliasesGroupBox)
spacerItem1 = QtGui.QSpacerItem(20, 38, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout_3.addItem(spacerItem1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem2)
self.revertButton = QtGui.QPushButton(self.frame)
self.revertButton.setObjectName("revertButton")
self.horizontalLayout.addWidget(self.revertButton)
self.applyButton = QtGui.QPushButton(self.frame)
self.applyButton.setObjectName("applyButton")
self.horizontalLayout.addWidget(self.applyButton)
self.verticalLayout_3.addLayout(self.horizontalLayout)
self.horizontalLayout_3.addWidget(self.splitter)
self.searchLabel.setBuddy(self.searchEdit)
self.nameLabel.setBuddy(self.nameEdit)
self.profileButton.setBuddy(self.profileComboBox)
self.addressLabel.setBuddy(self.addressEdit)
self.locationLabel.setBuddy(self.locationComboBox)
self.secureLabel.setBuddy(self.secureComboBox)
self.UUIDLabel.setBuddy(self.UUIDEdit)
self.passwordLabel.setBuddy(self.passwordEdit)
self.retranslateUi(clientEditorForm)
QtCore.QMetaObject.connectSlotsByName(clientEditorForm)
def retranslateUi(self, clientEditorForm):
clientEditorForm.setWindowTitle(QtGui.QApplication.translate("clientEditorForm", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.searchLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Search", None, QtGui.QApplication.UnicodeUTF8))
self.clearButton.setText(QtGui.QApplication.translate("clientEditorForm", "Clear", None, QtGui.QApplication.UnicodeUTF8))
self.nameLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Name", None, QtGui.QApplication.UnicodeUTF8))
self.profileButton.setText(QtGui.QApplication.translate("clientEditorForm", "Profile", None, QtGui.QApplication.UnicodeUTF8))
self.addressLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Address", None, QtGui.QApplication.UnicodeUTF8))
self.locationLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Location", None, QtGui.QApplication.UnicodeUTF8))
self.secureLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Secure", None, QtGui.QApplication.UnicodeUTF8))
self.UUIDLabel.setText(QtGui.QApplication.translate("clientEditorForm", "UUID", None, QtGui.QApplication.UnicodeUTF8))
self.passwordLabel.setText(QtGui.QApplication.translate("clientEditorForm", "Password", None, QtGui.QApplication.UnicodeUTF8))
self.aliasesGroupBox.setTitle(QtGui.QApplication.translate("clientEditorForm", "Aliases", None, QtGui.QApplication.UnicodeUTF8))
self.addButton.setText(QtGui.QApplication.translate("clientEditorForm", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.removeButton.setText(QtGui.QApplication.translate("clientEditorForm", "Remove", None, QtGui.QApplication.UnicodeUTF8))
self.revertButton.setText(QtGui.QApplication.translate("clientEditorForm", "Revert", None, QtGui.QApplication.UnicodeUTF8))
self.applyButton.setText(QtGui.QApplication.translate("clientEditorForm", "Apply", None, QtGui.QApplication.UnicodeUTF8))
Then my simple application:
import sys
from PySide import QtCore, QtGui
from clientEditorForm import Ui_clientEditorForm
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MyMainWindow, self).__init__(parent)
self.ui = Ui_clientEditorForm()
self.ui.setupUi(self)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = MyMainWindow()
myapp.show()
sys.exit(app.exec_())
However, when I try to run it, I get the following:
QLayout: Attempting to add QLayout "" to QMainWindow "clientEditorForm", which already has a layout
and a segmentation fault. I'm following the basic instructions in this tutorial but I can't tell what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明 PySide 中的 QSpacerItem 类存在错误。注释掉上面代码中的 QSpacerItem 实例可以使其正常工作。 PySide bugzilla 上有一份错误报告。
Turns out there is a bug in PySide with the QSpacerItem class. Commenting out the QSpacerItem instances in the code above makes it work just fine. There's a bug report on the PySide bugzilla.
首先,您使用的是 PySide(诺基亚)而不是 PyQt4(Riverbank 计算),尽管它们的 API 几乎相同,但它们不是同一个项目。 PySide 示例可在此处获取:
git clone git://gitorious.org/pyside/pyside-examples.git
的调用有关
我认为问题可能与您对try
。
我知道这似乎是同一件事,但我在使用 PyQt4 时遇到了类似的问题,而且据我所知,诺基亚的 PySide 也有同样的问题。它与 Python 拥有父对象还是由底层 C++ 对象拥有有关。至少尝试一下吧,不到5秒!
下面是我所基于的示例,它来自 PySide 的 git 存储库。
Firstly you are using PySide(Nokia) not PyQt4(Riverbank Computing), although their API's are nearly identical they are not the same project. The PySide examples are available here:
git clone git://gitorious.org/pyside/pyside-examples.git
I think the problem may have to do with your call of
try
instead.
I know it seems like it is the same thing, but I've ran into similar problems with super using PyQt4, and from what I can tell Nokia's PySide has the same troubles. It has something to do with weather the Python owns the parent or it's owned by an underlying C++ object. At least give it a try, it'll take less than 5 seconds!
Below is the example I'm basing this off of, it's from the git repo for PySide.