国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

wordpress加授權(quán)網(wǎng)絡(luò)優(yōu)化工程師證書

wordpress加授權(quán),網(wǎng)絡(luò)優(yōu)化工程師證書,做網(wǎng)站需要學(xué)什么軟件,網(wǎng)建會是什么意思1.簡介 QAbstractListModel是Qt框架中的一個抽象類,用于實現(xiàn)數(shù)據(jù)模型,用于在Qt的視圖組件中展示和編輯列表數(shù)據(jù)。與QAbstractTableModel類似,它也是一個抽象類,提供了一些基本的接口和默認(rèn)實現(xiàn),可以方便地創(chuàng)建自定義的…

1.簡介

QAbstractListModel是Qt框架中的一個抽象類,用于實現(xiàn)數(shù)據(jù)模型,用于在Qt的視圖組件中展示和編輯列表數(shù)據(jù)。與QAbstractTableModel類似,它也是一個抽象類,提供了一些基本的接口和默認(rèn)實現(xiàn),可以方便地創(chuàng)建自定義的列表數(shù)據(jù)模型。

QAbstractListModel的主要功能包括以下幾點:

  • 數(shù)據(jù)的獲取和設(shè)置:通過實現(xiàn)data()和setData()接口,可以用于獲取和設(shè)置列表中的數(shù)據(jù)??梢愿鶕?jù)自己的數(shù)據(jù)結(jié)構(gòu)和邏輯,在這兩個接口中進(jìn)行相關(guān)的操作。data()方法用于獲取指定索引位置的數(shù)據(jù),setData()方法用于設(shè)置指定索引位置的數(shù)據(jù)。
  • 列表項的管理:可以通過rowCount()方法獲取列表中的項數(shù)。也可以通過insertRows()和removeRows()方法動態(tài)地增加或刪除列表項。
  • 列表的顯示和編輯:可以通過實現(xiàn)displayRole和editRole相關(guān)方法來確定列表數(shù)據(jù)在視圖中的顯示和編輯方式。也可以通過實現(xiàn)flags()方法來指定每個列表項的編輯屬性。
  • 數(shù)據(jù)的排序:可以通過實現(xiàn)sort()方法來對列表中的數(shù)據(jù)進(jìn)行排序。

由于該模型提供了比QAbstractItemModel更專業(yè)的接口,因此不適合與樹視圖一起使用;如果您想提供一個用于此目的的模型,則需要對QAbstractItemModel進(jìn)行子類化。如果您需要使用多個列表模型來管理數(shù)據(jù),則可能更適合使用子類QAbstractTableModel。

繼承QAbstractListModel,需要重寫rowCount()、data()、insertRows()、removeRows()等函數(shù)。

  • rowCount()函數(shù)返回模型的行數(shù)。
  • data()函數(shù)返回指定索引處的數(shù)據(jù)。
  • insertRows()插入行
  • removeRows()刪除行

2.示例

聲明數(shù)據(jù)結(jié)構(gòu)體:

typedef struct _student
{QString name;int age;double score;
}Student;

重寫rowCount()、data()、insertRows()和removeRows()等函數(shù)。?

#ifndef MYLISTMODEL_H
#define MYLISTMODEL_H#include <QAbstractListModel>
#include <QObject>
#include <QList>typedef 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(QList<Student> students);// 返回列表中行的數(shù)量virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;// 返回指定索引處的數(shù)據(jù)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:QList<Student> m_lstStu;
};#endif // MYLISTMODEL_H#include "MyListModel.h"MyListModel::MyListModel(QObject *parent): QAbstractListModel(parent)
{}void MyListModel::update(QList<Student> students)
{m_lstStu = students;for(int i=0;i<m_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){//插入一個空的數(shù)據(jù)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.h"MyListModel *pModel = nullptr;ListForm::ListForm(QWidget *parent) :QWidget(parent),ui(new Ui::ListForm)
{ui->setupUi(this);//去除選中虛線框ui->listView->setFocusPolicy(Qt::NoFocus);//設(shè)置整行選中ui->listView->setSelectionBehavior(QAbstractItemView::SelectRows);pModel = new MyListModel(this);// 構(gòu)造數(shù)據(jù),更新界面QList<Student> students;QList<QString> nameList;nameList<<"張三"<<"李四"<<"王二"<<"趙五"<<"劉六";for (int i = 0; i < 5; ++i){Student student;student.name = nameList.at(i);student.age = qrand()%6 + 13;//隨機生成13到19的隨機數(shù)student.score = qrand()%20 + 80;//隨機生成0到100的隨機數(shù);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(row+1,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實現(xiàn)自定義TableModel-CSDN博客

Qt 插件開發(fā)詳解_qt插件化開發(fā)-CSDN博客

Qt 繼承QAbstractTableModel實現(xiàn)自定義TableModel-CSDN博客

?

http://m.aloenet.com.cn/news/42408.html

相關(guān)文章:

  • 做視頻小網(wǎng)站犯法嗎可口可樂營銷策劃方案
  • 做網(wǎng)站的控件新品牌推廣策略
  • 如何選擇丹陽網(wǎng)站建設(shè)百度榜單
  • 遂溪手機網(wǎng)站建設(shè)公司百度指數(shù)專業(yè)版app
  • 我想網(wǎng)關(guān)鍵詞優(yōu)化舉例
  • h網(wǎng)站建設(shè)網(wǎng)絡(luò)優(yōu)化大師手機版
  • 做企業(yè)網(wǎng)站的好處域名注冊平臺有哪些
  • photoshop網(wǎng)站視覺設(shè)計步驟seo引流什么意思
  • 山東淄博網(wǎng)站建設(shè)的公司百度快速排名化
  • 行業(yè)資訊網(wǎng)seo推廣軟件
  • 網(wǎng)頁設(shè)計實訓(xùn)報告代碼新手學(xué)seo
  • 小型公眾號開發(fā)seo網(wǎng)站推廣經(jīng)理
  • 武漢漢口做網(wǎng)站公司訊展網(wǎng)站優(yōu)化推廣
  • 湖北省建設(shè)質(zhì)量安全協(xié)會網(wǎng)站seo網(wǎng)站推廣專員招聘
  • 網(wǎng)站在阿里云備案免費數(shù)據(jù)統(tǒng)計網(wǎng)站
  • 禮品公司網(wǎng)站建設(shè)好的競價托管公司
  • 天津建設(shè)工程信息網(wǎng)專家sem 優(yōu)化價格
  • 網(wǎng)站上添加子欄目濰坊百度網(wǎng)站排名
  • 深圳網(wǎng)站建設(shè)公司是選擇寧波seo優(yōu)化公司
  • 備案上個人網(wǎng)站和企業(yè)網(wǎng)站的區(qū)別百度sem是什么意思
  • wordpress開啟多站點功網(wǎng)絡(luò)營銷有哪些特點
  • 網(wǎng)站優(yōu)化 代碼優(yōu)化互聯(lián)網(wǎng)優(yōu)化
  • 如何為網(wǎng)站開發(fā)app中公教育培訓(xùn)機構(gòu)官網(wǎng)
  • 便宜網(wǎng)站建設(shè)公司如何建立自己的網(wǎng)站平臺
  • 微信怎么做捐錢的網(wǎng)站網(wǎng)站推廣費用
  • 一站式裝修平臺杭州seo論壇
  • 網(wǎng)頁設(shè)計網(wǎng)站建設(shè)過程報告免費網(wǎng)站入口在哪
  • 石碣仿做網(wǎng)站seo技術(shù)分享博客
  • 知名跟單網(wǎng)站做信號提供方女教師網(wǎng)課入06654侵錄屏
  • 安徽做網(wǎng)站免費seo排名軟件