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

虚拟网站仿制教程大连百度推广代理商

虚拟网站仿制教程,大连百度推广代理商,青州网站搭建,佛山微网站推广一、模型/视图结构概述 基本原理#xff1a; Qt 的模型/视图#xff08;Model/View#xff09;架构将数据的存储和显示分离#xff0c;提高了代码的可维护性和复用性。模型#xff08;Model#xff09;#xff1a;负责存储和管理数据#xff0c;提供数据的访问接口 Qt 的模型/视图Model/View架构将数据的存储和显示分离提高了代码的可维护性和复用性。模型Model负责存储和管理数据提供数据的访问接口如获取数据、插入数据、修改数据、删除数据等。视图View负责显示数据不关心数据的存储和操作只根据模型的数据进行显示。代理Delegate负责在视图中渲染和编辑数据项提供了一种机制来定制数据的显示和编辑方式例如使用自定义的部件进行数据的编辑。 二、QAbstractItemModel 类 功能 是所有项模型的抽象基类定义了项模型必须实现的接口如 rowCount、columnCount、data、setData 等用于提供数据的存储和操作接口。可以自定义继承自 QAbstractItemModel 的模型类以满足不同的数据存储和操作需求。 三、QAbstractItemView 类 功能 是所有项视图的抽象基类提供了显示数据的通用接口如 setModel 用于关联一个模型视图会根据模型的数据进行显示和更新。常见的派生类有 QListView、QTreeView、QTableView 等分别用于列表、树状、表格形式的数据显示。 四、QStringListModel 类及示例程序功能实现 功能 存储一个字符串列表方便地用于 QListView 和 QComboBox 等视图的数据显示。 #include QApplication #include QListView #include QStringListModelint main(int argc, char *argv[]) {QApplication app(argc, argv);QStringListModel *model new QStringListModel;QStringList stringList;stringList Item 1 Item 2 Item 3;model-setStringList(stringList);QListView *listView new QListView;listView-setModel(model);listView-show();return app.exec(); }代码解释 创建一个 QStringListModel 并添加一些字符串元素。创建一个 QListView 并将 QStringListModel 设置为其模型QListView 将显示字符串列表中的元素。 五、自定义代理 自定义代理功能 允许用户自定义数据在视图中的显示和编辑方式例如使用自定义的部件进行数据的编辑或者添加一些特定的显示效果。 六、QStyledItemDelegate 类及设计自定义代理类 功能 提供了默认的数据项显示和编辑功能可作为自定义代理的基类。 #include QApplication #include QListView #include QStyledItemDelegate #include QPainter #include QStyleOptionViewItemclass CustomDelegate : public QStyledItemDelegate { protected:void paint(QPainter *painter, const QStyleOptionViewItem option, const QModelIndex index) const override{QStyleOptionViewItem opt option;initStyleOption(opt, index);// 自定义绘制painter-save();painter-setPen(Qt::red);painter-drawText(opt.rect, Qt::AlignCenter, index.data().toString());painter-restore();}QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem option, const QModelIndex index) const override{// 创建自定义编辑器QLineEdit *editor new QLineEdit(parent);return editor;}void setEditorData(QWidget *editor, const QModelIndex index) const override{QLineEdit *lineEdit qobject_castQLineEdit*(editor);if (lineEdit) {lineEdit-setText(index.data().toString());}}void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex index) const override{QLineEdit *lineEdit qobject_castQLineEdit*(editor);if (lineEdit) {model-setData(index, lineEdit-text());}}void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem option, const QModelIndex index) const override{editor-setGeometry(option.rect);} };int main(int argc, char *argv[]) {QApplication app(argc, argv);QStringListModel *model new QStringListModel;QStringList stringList;stringList Item 1 Item 2 Item 3;model-setStringList(stringList);QListView *listView new QListView;listView-setModel(model);CustomDelegate *delegate new CustomDelegate;listView-setItemDelegate(delegate);listView-show();return app.exec(); }代码解释 自定义 CustomDelegate 类继承自 QStyledItemDelegate。paint 方法用于自定义数据项的绘制这里将文本绘制为红色。createEditor 方法创建自定义的编辑部件这里是 QLineEdit。setEditorData 方法将模型数据设置到编辑器中。setModelData 方法将编辑器的数据更新到模型中。updateEditorGeometry 方法设置编辑器的位置和大小。 七、QFileSystemModel 和 QTreeView 类及示例程序功能实现 功能 QFileSystemModel 提供了文件系统的数据模型可以显示文件和目录。QTreeView 可以用来显示 QFileSystemModel 提供的数据。 #include QApplication #include QTreeView #include QFileSystemModelint main(int argc, char *argv[]) {QApplication app(argc, argv);QFileSystemModel *model new QFileSystemModel;model-setRootPath(QDir::homePath());QTreeView *treeView new QTreeView;treeView-setModel(model);treeView-setRootIndex(model-index(QDir::homePath()));treeView-show();return app.exec(); }代码解释 创建 QFileSystemModel 并设置根路径为用户的主目录。创建 QTreeView 并将 QFileSystemModel 设置为其模型。将 QTreeView 的根索引设置为用户主目录使其显示用户主目录下的文件和目录结构。
http://www.hkea.cn/news/14468748/

相关文章:

  • app网站制作公司施工企业平台
  • 怎么申请网站空间域名西安网站建设公司都有哪些
  • 有哪些网站可以推广深圳品牌手表
  • 宁波网站扔优化seo服务 文库
  • 郑州网站排名优化公司湖南企业网站制作公司
  • seo网站计划书wordpress 报名插件
  • 自己怎么建个网站赚钱phpmysql网站模板
  • 长治公司网站建设网站分为四个步骤开发建设
  • 大方网站制作wordpress 表单附件
  • 官方网站建设方法在线网站分析工具
  • nodejs 网站开发模块响应式网站发展
  • 网站制作公司天强科技深圳市营销型网站
  • 商城开发网站宁波网站建设明细报价
  • 做网站办贷款网易企业邮箱pop3设置
  • 网站运营方案ppt郑州网站建设冫汉狮网络
  • 陕西富通建设工程有限公司网站wordpress抖音插件
  • 乡镇网站建设内容规划网站服务器租用价格表
  • 注册网站域名的作用茂名网站开发公司推荐
  • 公司建设网站的请示网站建设 app
  • 做移动网站优化望城警务督察网站建设
  • 网站百度忽然搜索不到html5个人主页
  • 男女在浴室里做羞羞事网站全市网站建设情况摸底调查
  • 网站设计怎么做有效的域名解析后怎么建网站
  • 做网站前怎么写文档wordpress api文档下载
  • 网站获取客户信息需要备案吗企业管理培训课程培训机构
  • 做零售外贸网站有哪些一元购网站怎么做
  • 郑州网站seo费用海南房产信息网
  • 开发电商网站多少钱天蓝色美容网站
  • 石家庄市网站建设培训班龙岩做网站开发找哪家
  • 长丰网站制作春节网页制作素材