如果有人請幫助我,我想從這個類變量「self.item_clicked」值獲得第一至第二類PyQt的:從一個類傳遞值到另一個
謝謝提前
conn = sqlite3.connect('DBM.db')
conn.text_factory = str
c = conn.cursor()
#for row in c.execute('SELECT * FROM typem'):
# print(row)
class Second2(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Second2, self).__init__(parent)
#self.pushButton = QtGui.QPushButton("Close")
#self.setCentralWidget(self.pushButton)
self.setWindowTitle('Number')
self.setGeometry(500, 400, 100, 100)
self.label = QtGui.QLabel(self)
self.setCentralWidget(self.label)
self.label.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.label.setAlignment(Qt.AlignCenter)
def setValue(self, item):
select_item = c.execute('SELECT Num FROM typem WHERE Type=?', (item,))
print item
self.label.setText(item)
class First(QListWidget):
def __init__(self, parent=None):
super(First, self).__init__(parent)
self.add_items()
self.itemDoubleClicked.connect(self.item_click)
self.dialog = Second2(self)
def item_click(self, item):
self.item_clicked = item.text()
self.dialog.setValue(self.item_clicked)
self.dialog.show()
def add_items(self):
for row in c.execute('SELECT Type FROM typem'):
item = QListWidgetItem("{0}".format(row[0]))
self.addItem(item)
def main():
app = QtGui.QApplication(sys.argv)
main = First()
main.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
當你想要得到它時,你在哪裏創建了一個第一個類的對象? – eyllanesc
當我點擊列表中的項目去第二班時,我想獲得它 – ShwSvn
您將在第二班的哪一部分使用它? – eyllanesc