【发布时间】:2017-07-01 11:11:56
【问题描述】:
我一直在尝试将按钮连接到函数,但出现以下错误:
QObject.connect(b1,SIGNAL("clicked()"),GetBestMatch)
TypeError: arguments did not match any overloaded call:
QObject.connect(QObject, SIGNAL(), QObject, SLOT(), Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), callable, Qt.ConnectionType=Qt.AutoConnection): argument 1 has unexpected type 'NoneType'
QObject.connect(QObject, SIGNAL(), SLOT(), Qt.ConnectionType=Qt.AutoConnection): first argument of unbound method must have type 'QObject'
这是我写下的给出错误的连接代码:
QObject.connect(b1,SIGNAL("clicked()"),GetBestMatch)
我也尝试通过以下代码进行连接:
b1.clicked.connect(GetBestMatch)
并得到错误:
b1.clicked.connect(GetBestMatch)
AttributeError: 'NoneType' object has no attribute 'clicked'
我不知道我做错了什么。
我能够创建一个带有标签和按钮的网格,但不能将按钮连接到功能。这是图形用户界面代码:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def MainWindow():
app = QApplication(sys.argv)
screen_resolution = app.desktop().screenGeometry()
width, height = screen_resolution.width(), screen_resolution.height()
win = QWidget()
win.adjustSize()
grid=QGridLayout()
grid.setRowStretch(0, 1)
grid.setRowStretch(1, 1)
grid.setRowStretch(5, 1)
for i in range(0,5):
for j in range(0,4):
if i==0 and j==2:
l1=grid.addWidget(QLabel("Choose an option:"),i,j, 2, 2)
if i==2 and j==1:
b1=grid.addWidget(QPushButton("Get Best Match"),i,j)
elif i==2 and j==2:
b2=grid.addWidget(QPushButton("Button 2"),i,j)
elif i==2 and j==3:
b3=grid.addWidget(QPushButton("Button 3"),i,j)
b5=grid.addWidget(QLabel(""),3,4)
b4=grid.addWidget(QPushButton("Button 4"),2,4)
win.setLayout(grid)
win.setGeometry(100,100,width//2,height//2,)
win.setWindowTitle("Information on all tracking buses")
win.show()
win.setStyleSheet("""
.QPushButton {
height: 30px ;
width: 20px ;
}
.QLabel {
qproperty-alignment: AlignCenter;
font-size:12pt
}
""")
sys.exit(app.exec_())
def GetBestMatch():
print ("HI")
if __name__ == '__main__':
MainWindow()
布局完美无误。你能帮我解决这个问题吗?
【问题讨论】:
标签: python-3.x user-interface pyqt4