范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

QtMVC架构

  【1】代理应用示例源码
  用代码说事,比较靠谱。
  代码目录:三个自定义类,重实现QStyledItemDelegate类。main函数应用示例。
  (1)ComboDelegate.h   #ifndef COMBODELEGATE_H   #define COMBODELEGATE_H      #include       class ComboDelegate : public QStyledItemDelegate   {   public:       ComboDelegate(QObject *parent = NULL);    protected:      QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;      void setEditorData(QWidget *editor, const QModelIndex &index) const;      void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;      void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;  };    #endif // COMBODELEGATE_H
  (2)ComboDelegate.cpp   #include "ComboDelegate.h"   #include       ComboDelegate::ComboDelegate(QObject *parent)       : QStyledItemDelegate(parent)   {}      QWidget *ComboDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const   {      Q_UNUSED(option);      Q_UNUSED(index);        QStringList list;      list << "工人" << "农民" << "军人" << "律师";        QComboBox *pEditor = new QComboBox(parent);      pEditor->addItems(list);      pEditor->installEventFilter(const_cast(this));      return pEditor;  }    void ComboDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const  {      QString strText = index.model()->data(index).toString();      QComboBox *pCombox = NULL;      pCombox = static_cast(editor);      if (pCombox != NULL)      {          int nIndex = pCombox->findText(strText);          pCombox->setCurrentIndex(nIndex);      }  }    void ComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index)const  {      QComboBox *pCombox = NULL;      pCombox = static_cast(editor);      if (pCombox != NULL)      {          QString strText = pCombox->currentText();          model->setData(index, strText);      }  }    void ComboDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index)const  {      Q_UNUSED(index);     editor->setGeometry(option.rect);  }
  (3)DateDelegate.h   #ifndef DATEDELEGATE_H   #define DATEDELEGATE_H      #include       class DateDelegate : public QStyledItemDelegate   {   public:       DateDelegate(QObject *parent = NULL);    protected:      QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;      void setEditorData(QWidget *editor, const QModelIndex &index) const;      void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;      void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;  };    #endif // DATEDELEGATE_H
  (4)DateDelegate.cpp   #include "DateDelegate.h"   #include       DateDelegate::DateDelegate(QObject *parent)       : QStyledItemDelegate(parent)   {}      // 首先创建要进行代理的窗体   QWidget *DateDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const  {      Q_UNUSED(option);      Q_UNUSED(index);        QDateTimeEdit *pEditor = new QDateTimeEdit(parent);      // 一个日历的控件      pEditor->setDisplayFormat("yyyy-MM-dd");   // 日期时间的显示格式      pEditor->setCalendarPopup(true);   // 以下拉的方式显示      pEditor->installEventFilter(const_cast(this));  // 调用这个函数安装事件过滤器,使这个对象可以捕获QDateTimeEdit对象的事件      return pEditor;  }    // 这个是初始化作用,初始化代理控件的数据  void DateDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const  {    // 先用这个index返回这个model然后用这个model得到index对应的数据    QString strDate = index.model()->data(index).toString();    QDate date = QDate::fromString(strDate, Qt::ISODate);     // 根据QString类型得到相应的时间类型    QDateTimeEdit *pEditor = NULL;    pEditor = static_cast(editor);    // 强转为QDateTimeEdit*类型    if (pEditor != NULL)    {        pEditor->setDate(date);      // 设置代理控件的显示数据    }  }    // 将代理控件里面的数据更新到视图控件中  // void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;  void DateDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const  {    QDateTimeEdit *pEditor = NULL;    pEditor = static_cast(editor);    // 得到时间    if (pEditor != NULL)    {        QDate date = pEditor->date();    // 得到时间        model->setData(index, QVariant(date.toString(Qt::ISODate)));    // 把值放到相应的index里面    }  }    // 代理中数据的改变放到model中  // void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;  void DateDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const  {      Q_UNUSED(index);      editor->setGeometry(option.rect);  }
  (5)SpinDelegate.h   #ifndef SPINDELEGATE_H   #define SPINDELEGATE_H     #include       class SpinDelegate : public QStyledItemDelegate   {   public:       SpinDelegate(QObject *parent = NULL);    protected:      QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;      void setEditorData(QWidget *editor, const QModelIndex &index) const;      void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;      void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;  };    #endif // SPINDELEGATE_H
  (6)SpinDelegate.cpp   #include "SpinDelegate.h"      #include       SpinDelegate::SpinDelegate(QObject *parent)       : QStyledItemDelegate(parent)   {   }     QWidget *SpinDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const  {      Q_UNUSED(option);      Q_UNUSED(index);        QSpinBox *pEditor = new QSpinBox(parent);      pEditor->setRange(0, 30000);      pEditor->installEventFilter(const_cast(this));      return pEditor;  }    void SpinDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const  {      int value = index.model()->data(index).toInt();      QSpinBox *pSpinbox = NULL;      pSpinbox = static_cast(editor);      if (pSpinbox != NULL)      {          pSpinbox->setValue(value);      }  }    void SpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const  {      QSpinBox *pSpinbox = NULL;      pSpinbox = static_cast(editor);      if (pSpinbox != NULL)      {          int value = pSpinbox->value();          model->setData(index, value);      }  }    void SpinDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const  {      Q_UNUSED(index);        editor->setGeometry(option.rect);  }
  (7)main.cpp   #include    #include    #include    #include    #include    #include    #include    #include "DateDelegate.h"   #include "ComboDelegate.h"  #include "SpinDelegate.h"    int main(int argc, char *argv[])  {      QApplication a(argc, argv);        QStandardItemModel model(4, 4);      model.setHeaderData(0, Qt::Horizontal, QLatin1String("Name"));      model.setHeaderData(1, Qt::Horizontal, QLatin1String("Birthday"));      model.setHeaderData(2, Qt::Horizontal, QLatin1String("Job"));      model.setHeaderData(3, Qt::Horizontal, QLatin1String("Income"));        QFile file(QLatin1String("/mnt/liuy/info"));      if (!file.open(QIODevice::ReadOnly | QIODevice::Text))      {          qDebug() << "open the file failed...";          return -1;      }        QTextStream out(&file);      QString line;      model.removeRows(0, model.rowCount(QModelIndex()), QModelIndex());      int row = 0;      do      {          line = out.readLine();          if (!line.isEmpty())          {              model.insertRows(row, 1, QModelIndex());              QStringList pieces = line.split(",", QString::SkipEmptyParts);              model.setData(model.index(row, 0, QModelIndex()), pieces.value(0));              model.setData(model.index(row, 1, QModelIndex()), pieces.value(1));              model.setData(model.index(row, 2, QModelIndex()), pieces.value(2));              model.setData(model.index(row, 3, QModelIndex()), pieces.value(3));              ++row;          }      } while(!line.isEmpty());      file.close();        QTableView tableView;      tableView.setModel(&model); // 绑定Model      tableView.setWindowTitle(QLatin1String("Delegate"));        DateDelegate dateDelegate;      tableView.setItemDelegateForColumn(1, &dateDelegate); // 第一列代理      ComboDelegate comboDelegate;      tableView.setItemDelegateForColumn(2, &comboDelegate);// 第二列代理      SpinDelegate spinDelegate;      tableView.setItemDelegateForColumn(3, &spinDelegate); // 第三列代理        tableView.resize(500, 300); // 重置大小      tableView.show();        return a.exec();  }
  备注:此示例运行环境为UBuntu + Qt5.3.2
  【2】读取的信息文件
  文件info 内容如下(注意:文件格式): Liu,1977-01-05,工人,1500 Wang,1987-11-25,医生,2500 Sun,1967-10-05,军人,500 Zhang,1978-01-12,律师,4500
  【3】运行效果图
  运行效果图:
  第二列编辑图(时间日期控件):
  第三列编辑图(下拉框控件):
  第四列编辑图(微调框控件):

如何顺利当妈,听听过来人怎么说(建议收藏)本周姐妹茶话会话题是科学备孕指南这期的茶话会,请妈妈们给正在为备孕迷茫的姐妹一些建议吧科学备孕应该怎么备,有哪些事一定要做,有哪些备孕期的好物?一起来看看大家是怎么说的吧(作者娃娃只要你想生娃就尽管生,结不结婚并不重要!四川省开始放大招了,四川省生育登记服务管理办法将于2月15日起施行。主要修订以下四方面内容四川生育登记取消结婚限制取消办理生育登记时生育数量的限制简化生育登记的要求增加信息共享的要为什么孕期容易出现口腔问题?孕期的激素变化一般来说孕妈妈受到孕激素的变化抵抗力减弱的同时牙齿会产生充血,血管增生等现象,有些孕妈妈甚至会严重到牙龈肿胀发炎。孕期饮食习惯的改变怀孕后孕妈妈会特别容易饿,同时也会想从源头解决便秘问题?需要辩证,看看你是哪种类型便秘是现在很多人都感到困扰的问题,虽不是什么大病,但也难以根治。很多人都知道,香蕉西瓜绿豆等食物都有排毒通便的功效,但有些常便秘的人,吃多了以后就渐渐发现失效了,这时你就要考虑自己一天该喝多少水?怎么喝才刚刚好?霞姨来到神经外科,问道医生,我觉得头很痛,很胀,实在很不舒服。医师问从什么时候开始的呢?我一个月前听了某大师说,我们要多喝水净化身心,水是经过大师加持过的,一天要喝一万毫升。惠姨说健康饮食的基础健康饮食需做到膳食均衡,膳食均衡的基本原则是食物多样化。古代黄帝内经早就提出五谷为养五果为助五畜为益五菜为充的多样化饮食原则。中国居民膳食指南也推荐平均每天摄入12种以上食物,每周看王天一特大的微博后送牢骚太盛防肠断风物长宜放眼量共勉在王郑2023十番棋争霸赛以流产的方式落下帷幕时,王天一特大曾在直播间发言呼吁大家不要再攻击郑惟桐,他认为该事件持续发酵,势必会影响中国象棋的发展,对谁都没有好处。他还强调希望粉丝女排姐妹花贡献31分!拦网17比6碾压对手,巴西主攻空砍26分20222023赛季的巴西女排超级联赛第十二轮结束,具备争夺实力的乌贝兰迪亚海滩3比1击败了巴西利亚,海滩队的多米尼加攻手马丁内斯姐妹联手砍下31分,在拦网环节17比6大比分领先对波津MSG中有孩子们穿我球衣他们试图与我击掌ampampamp告诉我重回纽约直播吧1月19日讯今日NBA常规赛,奇才在客场116105战胜尼克斯。赛后,奇才球员波尔津吉斯接受了记者采访。谈到面对旧主尼克斯队,波津讲道好多了,对我的嘘声也少了,我想是球迷们对美国国际贸易委员会正式对OLED面板及其组件启动337调查科技战略美国国际贸易委员会正式对OLED面板及其组件启动337调查据中国贸易救济信息网1月27日消息,美国国际贸易委员会(ITC)投票决定对特定用于移动设备的有源矩阵有机发光二极管田富达新政协会议上最年轻的代表台湾民主自治同盟的优秀领导人,高山族人民的杰出代表,台湾民主自治同盟中央委员会原副主席,中国共产党的优秀党员田富达同志因病于2023年1月19日在北京逝世,享年93岁。田富达见证了
中国女排30横扫比利时队晋级八强,技术统计出炉10月9日中国女排对阵比利时队的生死战,这场比赛关系着两队谁能进入八强,所以两队都异常重视,都拿出120的战力对待比赛,结果中国队一扫03对阵意大利队的失利的阴霾,全队一传防守进攻(体育)乒乓球世乒赛团体赛男子决赛中国队夺冠(7)当日,在成都举行的第56届世界乒乓球团体锦标赛(决赛)男子决赛中,中国队以3比0战胜德国队,夺得冠军。10月9日,德国队选手邱党在比赛中回球,他以1比3不敌中国队选手马龙。新华社记炒房炒中药炒藏獒,50元变成4000万,为何如此热衷击鼓传花?1hr你知道1993年,北京的房价是多少钱吗?2000元左右一平。没想到北京的房价也这么接地气过吧?但是这种亲民的状态并没有维持多长时间。到了2000年左右,就已经涨到了3万。7年美国芯片巨头股价狂跌苹果蒸发6106亿10月7日,道标普三大美国股指低开低走,美国芯片股科技股所在的IT板块遭遇超大跌幅。据悉,芯片股最大跌幅到达14,而以特斯拉微软亚马逊等龙头为首的科技股也遭遇重创,分别跌幅6。32按了就得买,泰国那么多水果倒入河中,牌子上的字令游客愤怒对中国版图有所了解的人都知道中国的纬度所处在的温度带主要是温带,而我国的热带占比面积十分的狭小,因此一部分热带水果由于我国地界的原因难以栽种成熟或者说难以为它们形成一个良好的生长环云南旅游跟团后果,请谨慎观看作为一名爱到处跑的妹子,这两年出去玩踩的坑,也非常非常多了,最后总结出来跟团玩的话一定要跟当地团,这样可以很大概率避免踩坑,国庆前我们去云南耍也是一样,国旅的朋友帮我推荐了一家本地乡村民宿为谁建?建什么?如何借助乡村旅游实现乡村振兴?民宿发展需要与农业农村农民的空间要素民俗文化人文要素等深度融合。要在设计中将乡村民宿的自然环境历史渊源人文元素时代特征艺术色彩经营特色充分整合,既有情怀的淳朴又有时代创新的新潮和提98ampamp39ampamp39Q10G万象的来源98Q10G被称为万象星河宇宙之花万象即宇宙内外一切事物或景象。南朝宋谢灵运从游京口北固应诏诗皇心美阳泽,万象咸光昭。唐杜甫宿白沙驿诗万象皆春气,孤槎自客星。就词诗而言,已让我对这王菲与大S选择离婚,来源于自身强大的财力与勇气不合适的人是黑洞,永无止境吞噬你人生的另一半选择错了,那么往后余生的每一步都是错。你会尝尽人间疾苦,取舍两难。相貌和财富都不是那么重要,重要的是人品责任和担当,以及原生家庭刻在骨子乐山夹江二郎庙的来源和历史,感受一场传承千年的庙会文化!夹江头条创作挑战赛乐山夹江二郎庙位于四川省乐山市夹江县甘江镇九盘山,距夹江县城和乐山市区均十几公里,位于与新民村盘渡村艾中村毗邻,山中植被茂密,拥有原生态的清幽。创建于清代,整座庙宇坐这张我们无比熟悉的图片竟来源于环地球轨道上的一次地球自拍这张我们无比熟悉的图片竟来源于环地球轨道上的一次地球自拍202209302209风云之声导言我们的征途是星辰大海。当我们回顾家园,发现它竟如此之渺小的时候,我想每个人都会受到巨大的