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

珠海网站策划公司百度快照是干什么的

珠海网站策划公司,百度快照是干什么的,装修设计公司官网,公司网站建设多少费用兴田德润在哪里参考#xff1a;QT(7)-初识委托_qt 委托-CSDN博客 一、 1、 模型#xff1a;负责“组织”数据#xff1b; 视图#xff1a;负责“显示”数据#xff1b; 委托#xff1a;负责“修改”数据#xff1b; 2、委托#xff1a;在QT的MV模型中#xff0c;处理特定类型的…参考QT(7)-初识委托_qt 委托-CSDN博客 一、 1、 模型负责“组织”数据 视图负责“显示”数据 委托负责“修改”数据 2、委托在QT的MV模型中处理特定类型的数据控制数据的外观和行为 定制 数据 的“显示”和“编辑” 编辑日期,数值、渲染颜色,字体、 支持文本编辑器,下拉列表编辑器等、 更新编辑器的尺寸、证编辑器中的数据是否合法 3、委托应用场景 3.1表格和列表视图编辑单元格的数据、定制单元格外观 3.2 属性编辑器创建自定义的属性编辑器 3.3 文件对话框定制文件列表的外观 二、QT中的委托类 抽象基类 QAbstractItemDelegate-》QItemDelegate-》QStyledItemDelegate QStyledItemDelegate使用Qt Style Sheets来渲染单元格中的数据这样可以更好地与应用程序的外观保持一致。 三、委托类 关键函数 3.1 virtual函数 createEditor创建用于编辑特定单元格中数据的 编辑器 setEditorData编辑器被创建后被调用用于初始化设置编辑器的值。 setModelData在编辑器编辑完成后被调用用于将编辑器中数据更新到数据模型中 updateEditorGeometry用于设置编辑器的位置和大小。 一般通过继承 QStyledItemDelegate以上4个函数便可以实现简单的自定义委托。 3.2 其他函数 destroyEditor editorEvent helpEvent sizeHint 这些函数并没有重要和非重要之分需要根据不同的需求实现不同的函数达到想要的效果。 四、使用委托 实现功能 4.1 委托 实现功能1创建QSpinBox 编辑器、设置编辑器值、将编辑器中值保存的数据模型、设置编辑器位置 delegate.h文件#ifndef DELEGATE_H #define DELEGATE_H#include QStyledItemDelegate//! [0] class SpinBoxDelegate : public QStyledItemDelegate {Q_OBJECTpublic:SpinBoxDelegate(QObject *parent nullptr);QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem option,const QModelIndex index) const override;void setEditorData(QWidget *editor, const QModelIndex index) const override;void setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex index) const override;void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem option,const QModelIndex index) const override; }; //! [0]#endifdelegate.cpp文件#include delegate.h #include QSpinBox//! [0] SpinBoxDelegate::SpinBoxDelegate(QObject *parent): QStyledItemDelegate(parent) { } //! [0]//! [1] QWidget *SpinBoxDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem /* option */,const QModelIndex /* index */) const {QSpinBox *editor new QSpinBox(parent);editor-setFrame(false);editor-setMinimum(0);editor-setMaximum(100);return editor; } //! [1]//! [2] void SpinBoxDelegate::setEditorData(QWidget *editor,const QModelIndex index) const {int value index.model()-data(index, Qt::EditRole).toInt();QSpinBox *spinBox static_castQSpinBox*(editor);spinBox-setValue(value); } //! [2]//! [3] void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex index) const {QSpinBox *spinBox static_castQSpinBox*(editor);spinBox-interpretText();int value spinBox-value();model-setData(index, value, Qt::EditRole); } //! [3]//! [4] void SpinBoxDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem option,const QModelIndex /* index */) const {editor-setGeometry(option.rect); } //! [4]createEditor函数中定义了一个 QSpinBox类型的编辑器并对其进行了简单的初始化和设置 setEditorData函数中将模型中index位置的数据拿了出来并保存在了value中并将value设置到了编辑器中 setModelData函数中将编辑器中的数据取出来设置到模型中 updateEditorGeometry中对位置进行了设置editor-setGeometry(option.rect);不执行这个生成的控件在坐标原点 4.2 委托 实现功能2创建QDateEdit 编辑器、设置编辑器值、将编辑器中值保存的数据模型、设置编辑器位置 delegate.cpp文件#include delegate.h #include QSpinBox #include QDateEditQDateEdit::QDateEdit(QObject *parent): QStyledItemDelegate(parent) { }QWidget *QDateEdit::createEditor(QWidget *parent,const QStyleOptionViewItem /* option */,const QModelIndex /* index */) const { // QSpinBox *editor new QSpinBox(parent); // editor-setFrame(false); // editor-setMinimum(0); // editor-setMaximum(100);auto *editor new QDateEdit(parent);editor-setDisplayFormat(yyyy-MM-dd);return editor; }void QDateEdit::setEditorData(QWidget *editor,const QModelIndex index) const { // int value index.model()-data(index, Qt::EditRole).toInt(); // QSpinBox *spinBox static_castQSpinBox*(editor); // spinBox-setValue(value);auto value index.model()-data(index, Qt::EditRole).toDate();QDateEdit *dateEdit static_castQDateEdit*(editor);dateEdit-setDate(value); }void QDateEdit::setModelData(QWidget *editor, QAbstractItemModel *model,const QModelIndex index) const { // QSpinBox *spinBox static_castQSpinBox*(editor); // spinBox-interpretText(); // int value spinBox-value(); // model-setData(index, value, Qt::EditRole);auto dateEdit static_castQDateEdit*(editor);auto value dateEdit-date();model-setData(index,value,Qt::EditRole); }void QDateEdit::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem option,const QModelIndex /* index */) const {editor-setGeometry(option.rect); } 五、 按照这个思路那么只要改一下里面的编辑器就能实现不同的委托。想要实现不同的委托只要继承QStyledItemDelegate类并实现相应的函数就可以实现不同的委托。 密码委托下拉框委托QComboBox颜色选择委托图标委托等等甚至包括一些你自己定义的控件的委托。
http://www.pierceye.com/news/906462/

相关文章:

  • 河南双师培训网站html 路径 网站根路径
  • 专业定制网站企业如何注册公司营业执照
  • 福泉市自己的网站某个产品营销推广方案
  • 金坛市建设局网站微信网站有什么作用
  • 设计建网站今天的最新消息新闻
  • 电商行业建设网站ui网页设计培训学校
  • fineui 如何做网站私密浏览器免费版片视频动漫
  • 产地证是在哪个网站上做一起做网店下载安装
  • 舞钢市城乡建设局网站阿里巴巴网站谁做的
  • 巴彦淖尔市网站制作网站不收录怎么解决
  • 站群源码长春建设网站公司哪家好
  • 石家庄网站建设雨点牛wordpress qq登录免费
  • 有网站如何做淘宝客荆门市城乡建设管理局网站
  • 综合性门户网站列举如何拥有自己的微信小程序
  • 我图网类网站建设做外贸哪个网站最好
  • 做网站后台运营这个工作怎么样成都网络推广哪家好
  • angularjs做的网站有哪些wordpress 文章
  • 全国网站建设公司排名wordpress功能强大的主题
  • 做网站用c 还是php番禺制作网站平台
  • 营销网站运营的基本环节郑州大学现代远程教育 《网页设计与网站建设》个人主页
  • 网站建设合同是谁开的wordpress装主题需要ftp
  • 新乡门户网站建设方案开启wordpress upwn
  • 烟台企业自助建站系统浙江网站seo
  • 北京婚纱摄影网站珠海网站建设怎样
  • 用什么软件来做网站域名网安备案
  • 能打开各种网站的浏览器推荐制作小网站
  • 山东公司网站开发好看的个人博客主页
  • 长沙优化网站获客软件最新网页游戏排行榜2021
  • 学校网站 建设网络系统管理与维护电大考试题
  • 中文域名转码网站琼筑网站是哪家做的