当前位置: 首页 > news >正文

广州公司网站制作招聘信息免费建站网站 百度一下

广州公司网站制作招聘信息,免费建站网站 百度一下,女教师遭网课入侵直播录屏曝光视频,菏泽网页设计公司1.简介 QAbstractListModel是Qt框架中的一个抽象类#xff0c;用于实现数据模型#xff0c;用于在Qt的视图组件中展示和编辑列表数据。与QAbstractTableModel类似#xff0c;它也是一个抽象类#xff0c;提供了一些基本的接口和默认实现#xff0c;可以方便地创建自定义的…1.简介 QAbstractListModel是Qt框架中的一个抽象类用于实现数据模型用于在Qt的视图组件中展示和编辑列表数据。与QAbstractTableModel类似它也是一个抽象类提供了一些基本的接口和默认实现可以方便地创建自定义的列表数据模型。 QAbstractListModel的主要功能包括以下几点 数据的获取和设置通过实现data()和setData()接口可以用于获取和设置列表中的数据。可以根据自己的数据结构和逻辑在这两个接口中进行相关的操作。data()方法用于获取指定索引位置的数据setData()方法用于设置指定索引位置的数据。列表项的管理可以通过rowCount()方法获取列表中的项数。也可以通过insertRows()和removeRows()方法动态地增加或删除列表项。列表的显示和编辑可以通过实现displayRole和editRole相关方法来确定列表数据在视图中的显示和编辑方式。也可以通过实现flags()方法来指定每个列表项的编辑属性。数据的排序可以通过实现sort()方法来对列表中的数据进行排序。 由于该模型提供了比QAbstractItemModel更专业的接口因此不适合与树视图一起使用如果您想提供一个用于此目的的模型则需要对QAbstractItemModel进行子类化。如果您需要使用多个列表模型来管理数据则可能更适合使用子类QAbstractTableModel。 继承QAbstractListModel需要重写rowCount()、data()、insertRows()、removeRows()等函数。 rowCount()函数返回模型的行数。data()函数返回指定索引处的数据。insertRows()插入行removeRows()删除行 2.示例 声明数据结构体 typedef struct _student {QString name;int age;double score; }Student; 重写rowCount()、data()、insertRows()和removeRows()等函数。  #ifndef MYLISTMODEL_H #define MYLISTMODEL_H#include QAbstractListModel #include QObject #include QListtypedef struct _student {QString name;int age;double score; }Student;class MyListModel : public QAbstractListModel {Q_OBJECT public:MyListModel(QObject *parent nullptr);enum RoleNames{Name,Age,Score};public://更新void update(QListStudent students);// 返回列表中行的数量virtual int rowCount(const QModelIndex parent QModelIndex()) const;// 返回指定索引处的数据virtual QVariant data(const QModelIndex index, int role Qt::DisplayRole) const;//插入行virtual bool insertRows(int row, int count, const QModelIndex parent QModelIndex());//删除行virtual bool removeRows(int row, int count, const QModelIndex parent QModelIndex());private:QListStudent m_lstStu; };#endif // MYLISTMODEL_H#include MyListModel.hMyListModel::MyListModel(QObject *parent): QAbstractListModel(parent) {}void MyListModel::update(QListStudent students) {m_lstStu students;for(int i0;im_lstStu.size();i){beginInsertRows(QModelIndex(),i,i);endInsertRows();} }int MyListModel::rowCount(const QModelIndex parent) const {Q_UNUSED(parent);return m_lstStu.size(); }QVariant MyListModel::data(const QModelIndex index, int role) const {if(!index.isValid())return QVariant();int nRow index.row();Student stu m_lstStu.at(nRow);if (role Qt::DisplayRole || role Qt::EditRole){QString ret QString(%1_%2_%3).arg(stu.name).arg(stu.age).arg(stu.score);return ret;}return QVariant(); }bool MyListModel::insertRows(int row, int count, const QModelIndex parent) {if (row 0 row m_lstStu.size()){beginInsertRows(parent, row, row count - 1);for (int i 0; i count; i){//插入一个空的数据Student stu;stu.name QString();stu.age 0;stu.score 0;m_lstStu.insert(row, stu);}endInsertRows();return true;}return false; }bool MyListModel::removeRows(int row, int count, const QModelIndex parent) {if (row 0 row count m_lstStu.size()){beginRemoveRows(parent, row, row count - 1);for (int i 0; i count; i){m_lstStu.removeAt(row);}endRemoveRows();return true;}return false; } 使用示例 #include ListForm.h #include ui_ListForm.h #include MyListModel.hMyListModel *pModel nullptr;ListForm::ListForm(QWidget *parent) :QWidget(parent),ui(new Ui::ListForm) {ui-setupUi(this);//去除选中虚线框ui-listView-setFocusPolicy(Qt::NoFocus);//设置整行选中ui-listView-setSelectionBehavior(QAbstractItemView::SelectRows);pModel new MyListModel(this);// 构造数据更新界面QListStudent students;QListQString nameList;nameList张三李四王二赵五刘六;for (int i 0; i 5; i){Student student;student.name nameList.at(i);student.age qrand()%6 13;//随机生成13到19的随机数student.score qrand()%20 80;//随机生成0到100的随机数;students.append(student);}pModel-update(students);ui-listView-setModel(pModel); }ListForm::~ListForm() {delete ui; }void ListForm::on_btnInsert_clicked() {if(!pModel)return;int row ui-listView-currentIndex().row();if(row 0)return;pModel-insertRows(row1,1); }void ListForm::on_btnDel_clicked() {if(!pModel)return;int row ui-listView-currentIndex().row();if(row 0)return;pModel-removeRows(row,1); }3.推荐 Qt 继承QAbstractTableModel实现自定义TableModel-CSDN博客 Qt 插件开发详解_qt插件化开发-CSDN博客 Qt 继承QAbstractTableModel实现自定义TableModel-CSDN博客
http://www.dnsts.com.cn/news/198642.html

相关文章:

  • 可以做网站吗如何做网站内链优化
  • 梧州网站建设有哪些wordpress更换主题帖子封面不显示
  • 微网站和h5有什么区别多商户商城源码下载
  • 网站建设相关的书籍发布友情链接
  • 北京网站seo公司外贸公司网站制作价格
  • 高职高专图书馆网站建设首都在线官网
  • 企业网站建立教程网页设计的背景与意义
  • 建设银行 杭州招聘网站wordpress 批量加密
  • 做视频网站 买带宽如何做 行业社交类网站
  • 行业网站建设的开发方案数据来源于网站需如何做脚注
  • 自己做的网站怎么传到空间啊东莞建网站公司平台
  • 站群建站系统大悟网站制作
  • 网站文章发布wordpress模板字体修改
  • 网站怎么做外部优化高端网站建设 司法
  • 淄博周村网站建设定制成都百度推广的关键词
  • 潍坊科技网站建设昆明网站的优化
  • 好看的企业网站源码互联网网站排名
  • 嘉兴企业网站制作贵阳小程序开发
  • 江西建设信息港网站wordpress手机双模板
  • 黑龙江 网站建设企业网站用什么做
  • 有没有可以做物理实验的网站服务器 wordpress 邮件
  • 遵义县住房和城乡建设局网站网站的技术建设
  • 贵州网站开发哪家好杭州百度人工优化
  • 智慧团建网站登录入口手机版平面设计公司网站建设费用
  • 网站怎么做推广和宣传语网站商业授权
  • 岳阳网站建设推广wordpress 导出
  • 网站设计教程视频下载公司名称查重系统
  • 11108给换成119333做网站做网站哪个语言快
  • 南京电商网站建设公司有没有好一点的网站
  • 描述网站建设的基本流程html自动播放视频