简单的学生信息管理系统(VS+QT)

说明:

作为练习的学生管理系统,使用vs2015,qt5.10完成(未使用数据库)。

上图:

在这里插入图片描述

功能描述 :

1.查找,导入,导出功能未完善,暂不可用
2.新建,删除,修改功能正常
3.在左侧输入数据点击新建,tablewidget显示对应数据
4.tablewidget点击某个数据,点击删除即可删除数据
5.点击某个数据,左侧属性栏显示对应数据,此时修改属性栏数据并点击更改即可完成修改

源码:

StudentInfo.h

#pragma once
#include <QtWidgets/QMainWindow>
#include <QList>
#include <QDebug>

#include "ui_StudentInfo.h"

class StudentInfo : public QWidget
{
	Q_OBJECT

public:
	StudentInfo(QWidget *parent = Q_NULLPTR);
	~StudentInfo();

private slots:
	void createInfo();                  //新建
	void deleteInfo();					//删除
	void searchInfo();					//查找信息
	void changeInfo();					//更改信息
	void showInfo(int,int);					//点击表格某行显示信息之属性栏

private:
	Ui::StudentInformation ui;
	QList<QString> m_studentList;
	QString m_name;
	bool m_sex;
	int m_age;
	int m_grade;
	void init();
	void initConnect();
	void getInfo();						//获取属性栏信息
	
};

StudentInfo.cpp

#include "StudentInfo.h"
StudentInfo::StudentInfo(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	init();
	initConnect();
}

StudentInfo::~StudentInfo()
{

}

void StudentInfo::getInfo()
{
	m_studentList.clear();
	m_studentList.append(ui.nameEdit->text());
	m_studentList.append(ui.sexEdit->text());
	m_studentList.append(ui.ageEdit->text());
	m_studentList.append(ui.gradeEdit->text());
}

void StudentInfo::showInfo(int row,int)
{
	row = ui.studentTable->currentRow();
	ui.nameEdit->setText(ui.studentTable->item(row,0 )->text() );
	ui.sexEdit->setText(ui.studentTable->item(row, 1)->text());
	ui.ageEdit->setText(ui.studentTable->item(row, 2)->text());
	ui.gradeEdit->setText(ui.studentTable->item(row, 3)->text());
}

void StudentInfo::createInfo()
{
	getInfo();
	int row = 0;
	row = ui.studentTable->rowCount();
	ui.studentTable->setRowCount(row + 1);
	for (int i = 0;i < 4;i++)
		ui.studentTable->setItem(row, i, new QTableWidgetItem(m_studentList.at(i)));

}

void StudentInfo::deleteInfo()
{
	ui.studentTable->removeRow(ui.studentTable->currentRow());
}

void StudentInfo::searchInfo()
{
}

void StudentInfo::changeInfo()
{
	ui.studentTable->setSelectionMode(QAbstractItemView::SingleSelection); //设置选择模式,选择单行
	getInfo();
	for (int i = 0;i < 4;i++)
		ui.studentTable->setItem(ui.studentTable->currentRow(), i, new QTableWidgetItem(m_studentList.at(i)));
}

void StudentInfo::init()
{
	this->setWindowTitle(QStringLiteral("学生信息表"));
	/*设置表格为整行选中*/
	ui.studentTable->setSelectionBehavior(QAbstractItemView::SelectRows);
	
}

void StudentInfo::initConnect()
{
	connect(ui.createButton, SIGNAL(clicked()), this, SLOT(createInfo()));
	connect(ui.deleteButton, SIGNAL(clicked()), this, SLOT(deleteInfo()));
	connect(ui.searchButton, SIGNAL(clicked()), this, SLOT(searchInfo()));
	connect(ui.changeButton, SIGNAL(clicked()), this, SLOT(changeInfo()));
	connect(ui.studentTable, SIGNAL(cellClicked(int,int)), this, SLOT(showInfo(int,int)));
}

StudentInfo.ui:

在这里插入图片描述
(PS:一个简单的练习,如果有什么不对欢迎指正!)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰封的雪绒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值