首页 > 解决方案 > 使用python在表格视图中显示来自不同表格的特定数据

问题描述

我想在表模型中完全显示 SQL 代码中的选定数据

def display_user_table(self):
        header = ['Pupil Id','First Name','Last Name','Year Level','Plate Number', 'Car Brand', 'Car Colour' ]
    data = show_pupil_table()
    self.table_model = MyTableModel(self, data, header)
    self.tableView.setModel(self.table_model)
    self.tableView.resizeColumnsToContents()
    self.tableView.resizeRowsToContents()
    self.tableView.horizontalHeader().setStretchLastSection(True)

下面是我在表格模型中显示数据的代码

def show_pupil_table():
    with ConnectionPool() as cursor:
        cursor.execute('''SELECT pupil_first_name, pupil_last_name, year_level,plate_number, car_brand,car_colour
FROM pupil_info
JOIN family_pupil fp on pupil_info.pupil_id = fp.pupil_id
JOIN family_car fc on fp.family_id = fc.family_id
JOIN car_info ci on fc.car_id = ci.car_id;''')
        return cursor.fetchall()

但它只显示了这一点

我的输出

我理想的输出是这样

理想输出

标签: pythonpyqt

解决方案


推荐阅读