def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = Ui_Student_schedule() self.ui.setupUi(self) self.conn() Student_query = QSqlQuery() Student_query.exec_("select Student_name from Student") model = QSqlQueryModel() model.setQuery(Student_query) self.ui.Student_listView.setModel(model) self.ui.schedule_btn.setEnabled(False) self.ui.Search_btn.clicked.connect(self.search_student) self.ui.schedule_btn.clicked.connect(self.print_schedule) self.ui.Student_listView.clicked.connect(self.select_Student)
def __init__(self): QtGui.QMainWindow.__init__(self) self.ui = Ui_Student_schedule() self.ui.setupUi(self) self.conn() Student_query = QSqlQuery() #get student name for user choosing Student_query.exec_( "select Student_name from Student ORDER BY Student_name") model = QSqlQueryModel() model.setQuery(Student_query) #populate listview by student's name self.ui.Student_listView.setModel(model) #disable button when the focus is not on the list self.ui.schedule_btn.setEnabled(False) self.ui.Search_btn.clicked.connect(self.search_student) self.ui.schedule_btn.clicked.connect(self.print_schedule) self.ui.Student_listView.clicked.connect(self.select_Student) self.ui.cancel_btn.clicked.connect(self.close)