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

沈阳酒店企业网站制作公司营销系统平台

沈阳酒店企业网站制作公司,营销系统平台,cms网站开发需要学什么,关键词做网站标题是什么意思这是我对 Qt 的 model/view 内容理解的第二篇 blog#xff0c;在第一篇文章中#xff0c;介绍 QTableView 和 QAbstractTableModel#xff0c;实现显示了对数据源的显示#xff0c;但是显示的格式和修改的模式都是按照 View 控件的自显示方式。在此#xff0c;使用 Qt 自带…这是我对 Qt 的 model/view 内容理解的第二篇 blog在第一篇文章中介绍 QTableView 和 QAbstractTableModel实现显示了对数据源的显示但是显示的格式和修改的模式都是按照 View 控件的自显示方式。在此使用 Qt 自带的 QStyledItemDelegate 类实现对特定行 / 列的显示 / 修改模式实现实现过程中不出现对 item 的代码生成对 item 的生成由程序自动完成。 在此同样以《c gui programming with Qt4》中的 trackEditor 例子作一讲解。 在此我们首先应当考虑以下几个问题 1有一个代理类加到 View 中处理特定的 View 内容。 2代理类要完成以下几项工作a当用户修改数据时生成用户要求的控件用户每次修改数据时在相应的位置都会生成控件所以当控件用完后应 del 释放资源。b设置在生成的修改控件中显示的内容。c设置要写到 model 中的数据内容。d设置当结束修改数据后View 显示的内容。 在此我们需要实现以下 4 个类。 /** brief 保存显示数据的类。 */ class Track/** brief 继承的委托类。 */ class TrackDelegate : public QStyledItemDelegate/** brief 继承的模型类。 */ class TrackModel : public QAbstractTableModel/** brief 用于组装显示的控件类。 */ class TrackEditor : public QDialog 在此Track TrackModel TrackEditor 的功能在 Qt model/view 理解 1 中做过介绍在此只列出 code不再过多介绍。在此主要介绍 TrackDelegate。 Track h 文件 #ifndef TRACK_H #define TRACK_H#include QString/**projectName ItemViewauthor qiaoweidate 2018-12-22version 1.0description 保存的音频数据包括音频名称和时长 **/ class Track { public:explicit Track(const QString title , int duration 0);QString getTitle() const;void setTitle(const QString title);int getDuration() const;void setDuration(int duration);private:/**author qioaweidate 2018-12-22description 音频名称**/QString title_;/**author qioaweidate 2018-12-22description 音频时长单位秒**/int duration_; };#endif // TRACK_H Track.cpp #include track.hTrack::Track(const QString title, int duration) :title_(title),duration_(duration) {}QString Track::getTitle() const {return title_; }void Track::setTitle(const QString title) {title_ title; }int Track::getDuration() const {return duration_; }void Track::setDuration(int duration) {duration_ duration; } TrackModel.h #ifndef TRACKMODEL_H#define TRACKMODEL_H#include QWidget #include QAbstractTableModel #include QList #include track.h #include QObject/**brief 继承的模型类。 */ class TrackModel : public QAbstractTableModel {Q_OBJECTpublic:explicit TrackModel(QListTrack* tracks, QObject* parent 0);~TrackModel();virtual int rowCount(const QModelIndex parent) const;virtual int columnCount(const QModelIndex parent) const;virtual QVariant data(const QModelIndex index, int role) const;virtual bool setData(const QModelIndex index,const QVariant value,int role);virtual Qt::ItemFlags flags(const QModelIndex index) const;private:QListTrack* tracks; };#endif // TRACKMODEL_H TrackEditor h 文件 #ifndef TRACKEDITOR_H#define TRACKEDITOR_H#include QDialog#include track.hQT_BEGIN_NAMESPACE class QTableView; class TrackModel; class QAbstractTableModel; QT_END_NAMESPACEnamespace Ui { class TrackEditor; }/**brief 用于组装显示的控件类。 */ class TrackEditor : public QDialog {Q_OBJECTpublic:explicit TrackEditor(QListTrack* tracks, QWidget *parent 0);~TrackEditor();private:Ui::TrackEditor *ui;QTableView* tableView;TrackModel* model;//QAbstractTableModel* model; };#endif // TRACKEDITOR_H TrackDelegate h 文件 #ifndef TRACKDELEGATE_H#define TRACKDELEGATE_H#include QObject #include QStyledItemDelegateQT_BEGIN_NAMESPACE class QPainter; QT_END_NAMESPACE/**brief 继承的委托类。 */ class TrackDelegate : public QStyledItemDelegate { public:explicit TrackDelegate(QObject* parent 0);~TrackDelegate();virtual QWidget* createEditor(QWidget *parent,const QStyleOptionViewItem option,const QModelIndex index) const;virtual void setEditorData(QWidget* parent,const QModelIndex index) const;virtual void setModelData(QWidget* editor,QAbstractItemModel* model,const QModelIndex index) const;virtual void updateEditorGeometry(QWidget* editor,const QStyleOptionViewItem option,const QModelIndex index) const;virtual void paint(QPainter* painter,const QStyleOptionViewItem option,const QModelIndex index) const;virtual QSize sizeHint(const QStyleOptionViewItem option,const QModelIndex index) const;private:bool isRightColumn(const QModelIndex index, const int column) const; private slots:void commitAndCloseEditor();private:static const int columnNumber; };#endif // TRACKDELEGATE_H TrackDelegate cpp 文件 #include trackdelegate.h #include QTimeEdit #include QPainter #include QApplication#include trackmodel.hconst int TrackDelegate::columnNumber 1;TrackDelegate::TrackDelegate(QObject* parent) :QStyledItemDelegate(parent) {}TrackDelegate::~TrackDelegate() {}QWidget* TrackDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem option,const QModelIndex index) const {if (isRightColumn(index, TrackDelegate::columnNumber)) {QTimeEdit *timeEdit new QTimeEdit(parent);timeEdit-setDisplayFormat(hh:mm);//当控件结束编辑内容时触发释放资源connect(timeEdit, QTimeEdit::editingFinished,this, TrackDelegate::commitAndCloseEditor);//int secs index.model()-data(index, Qt::DisplayRole).toInt();int secs index.model()-data(index, Qt::EditRole).toInt();QTime time(secs / 60, secs % 60);timeEdit-setTime(time);return timeEdit;} else {return QStyledItemDelegate::createEditor(parent,option,index);} }void TrackDelegate::setEditorData(QWidget *editor, const QModelIndex index) const {if ( !index.isValid()) {return;}QTimeEdit* timeEditor qobject_castQTimeEdit*(editor);if ( !timeEditor) {return;}if (isRightColumn(index, TrackDelegate::columnNumber)) {int secs index.model()-data(index, Qt::EditRole).toInt();QTime time(secs / 60, secs % 60);timeEditor-setTime(time);} else {QStyledItemDelegate::setEditorData(editor, index);} }void TrackDelegate::setModelData(QWidget *editor,QAbstractItemModel *model,const QModelIndex index) const {if ( !index.isValid()) {return;}QTimeEdit* timeEditor qobject_castQTimeEdit*(editor);if ( !timeEditor) {return;}if (isRightColumn(index, TrackDelegate::columnNumber)) {QTime time timeEditor-time();int secs time.hour() * 60 time.minute()model-setData(index, secs, Qt::EditRole);} else {QStyledItemDelegate::setModelData(editor,model,index);} }void TrackDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem option,const QModelIndex index) const {Q_UNUSED(index);editor-setGeometry(option.rect); }void TrackDelegate::paint(QPainter *painter,const QStyleOptionViewItem option,const QModelIndex index) const {if (isRightColumn(index, TrackDelegate::columnNumber)) {int secs index.model()-data(index, Qt::EditRole).toInt();QString text QString(%1:%2).arg(secs / 60, 2, 10, QChar(0)).arg(secs % 60, 2, 10, QChar(0));//获取项风格设置QStyleOptionViewItem myOption option;myOption.displayAlignment Qt::AlignRight | Qt::AlignVCenter;painter-drawText(option.rect, text);} else {QStyledItemDelegate::paint(painter, option, index);} }QSize TrackDelegate::sizeHint(const QStyleOptionViewItem option,const QModelIndex index) const {return option.rect.size(); }void TrackDelegate::commitAndCloseEditor() {QTimeEdit* editor qobject_castQTimeEdit*(sender());emit commitData(editor);emit closeEditor(editor); }bool TrackDelegate::isRightColumn(const QModelIndex index,const int column) const {if ( !index.isValid()) {return false;}if (index.column() column) {return true;} else {return false;} } createEditor 用于创建用户自己需要的显示数据控件。 setEditorData 用于设置显示控件中显示的具体数据信息。 setModelData 用户设置模型的数据也可理解为当显示的数据发生变化后用户 update 模型数据保持显示 / 储存内容一致。 paint 由用户自己绘制要显示的内容信息很重要当你点击时间框修改时间要改的内容为原显示内容并允许你修改而不是数据变为 00:00让你修改。 commitAndCloseEditor 创建关于 commitData 和 closeEditor 的信号槽链接保证当代理控件的数据修改完成后释放信号保存数据保存数据步骤由系统自动完成。 在此要求注意内容 在 TrackModel 类中的 setData 方法应当注意data 的值应从 value 得出而不是通过 model 的 data 得出model 得出的数据是原来保存的而不是用户修改的。
文章转载自:
http://www.morning.pyncm.cn.gov.cn.pyncm.cn
http://www.morning.kfhm.cn.gov.cn.kfhm.cn
http://www.morning.wphzr.cn.gov.cn.wphzr.cn
http://www.morning.knjj.cn.gov.cn.knjj.cn
http://www.morning.jkftn.cn.gov.cn.jkftn.cn
http://www.morning.dbnpz.cn.gov.cn.dbnpz.cn
http://www.morning.hmjasw.com.gov.cn.hmjasw.com
http://www.morning.dnvhfh.cn.gov.cn.dnvhfh.cn
http://www.morning.mpszk.cn.gov.cn.mpszk.cn
http://www.morning.fmznd.cn.gov.cn.fmznd.cn
http://www.morning.mrfr.cn.gov.cn.mrfr.cn
http://www.morning.pzbqm.cn.gov.cn.pzbqm.cn
http://www.morning.ghgck.cn.gov.cn.ghgck.cn
http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn
http://www.morning.txltb.cn.gov.cn.txltb.cn
http://www.morning.jftl.cn.gov.cn.jftl.cn
http://www.morning.mtsck.cn.gov.cn.mtsck.cn
http://www.morning.pljdy.cn.gov.cn.pljdy.cn
http://www.morning.xnymt.cn.gov.cn.xnymt.cn
http://www.morning.swyr.cn.gov.cn.swyr.cn
http://www.morning.tldhq.cn.gov.cn.tldhq.cn
http://www.morning.muniubangcaishui.cn.gov.cn.muniubangcaishui.cn
http://www.morning.xrnh.cn.gov.cn.xrnh.cn
http://www.morning.ywzqk.cn.gov.cn.ywzqk.cn
http://www.morning.jxjrm.cn.gov.cn.jxjrm.cn
http://www.morning.mkhwx.cn.gov.cn.mkhwx.cn
http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn
http://www.morning.qqfcf.cn.gov.cn.qqfcf.cn
http://www.morning.nzmhk.cn.gov.cn.nzmhk.cn
http://www.morning.clwhf.cn.gov.cn.clwhf.cn
http://www.morning.nmfml.cn.gov.cn.nmfml.cn
http://www.morning.qfmns.cn.gov.cn.qfmns.cn
http://www.morning.ktpzb.cn.gov.cn.ktpzb.cn
http://www.morning.rjyd.cn.gov.cn.rjyd.cn
http://www.morning.spwm.cn.gov.cn.spwm.cn
http://www.morning.rmyt.cn.gov.cn.rmyt.cn
http://www.morning.dygsz.cn.gov.cn.dygsz.cn
http://www.morning.tfrmx.cn.gov.cn.tfrmx.cn
http://www.morning.wzjhl.cn.gov.cn.wzjhl.cn
http://www.morning.nmhpq.cn.gov.cn.nmhpq.cn
http://www.morning.piekr.com.gov.cn.piekr.com
http://www.morning.xpzgg.cn.gov.cn.xpzgg.cn
http://www.morning.dgpxp.cn.gov.cn.dgpxp.cn
http://www.morning.qhvah.cn.gov.cn.qhvah.cn
http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn
http://www.morning.rdng.cn.gov.cn.rdng.cn
http://www.morning.phechi.com.gov.cn.phechi.com
http://www.morning.ckdgj.cn.gov.cn.ckdgj.cn
http://www.morning.brwei.com.gov.cn.brwei.com
http://www.morning.tqrxm.cn.gov.cn.tqrxm.cn
http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn
http://www.morning.xhrws.cn.gov.cn.xhrws.cn
http://www.morning.gwxwl.cn.gov.cn.gwxwl.cn
http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn
http://www.morning.wbxr.cn.gov.cn.wbxr.cn
http://www.morning.jgzmr.cn.gov.cn.jgzmr.cn
http://www.morning.rkmhp.cn.gov.cn.rkmhp.cn
http://www.morning.rfpxq.cn.gov.cn.rfpxq.cn
http://www.morning.mszls.cn.gov.cn.mszls.cn
http://www.morning.xcjbk.cn.gov.cn.xcjbk.cn
http://www.morning.dfmjm.cn.gov.cn.dfmjm.cn
http://www.morning.sflnx.cn.gov.cn.sflnx.cn
http://www.morning.pbzlh.cn.gov.cn.pbzlh.cn
http://www.morning.cjxqx.cn.gov.cn.cjxqx.cn
http://www.morning.cjqcx.cn.gov.cn.cjqcx.cn
http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn
http://www.morning.rtkgc.cn.gov.cn.rtkgc.cn
http://www.morning.qmbtn.cn.gov.cn.qmbtn.cn
http://www.morning.paoers.com.gov.cn.paoers.com
http://www.morning.bfrff.cn.gov.cn.bfrff.cn
http://www.morning.hjwkq.cn.gov.cn.hjwkq.cn
http://www.morning.hhfqk.cn.gov.cn.hhfqk.cn
http://www.morning.jpfpc.cn.gov.cn.jpfpc.cn
http://www.morning.gblrn.cn.gov.cn.gblrn.cn
http://www.morning.wqfj.cn.gov.cn.wqfj.cn
http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn
http://www.morning.rjnm.cn.gov.cn.rjnm.cn
http://www.morning.huxinzuche.cn.gov.cn.huxinzuche.cn
http://www.morning.xmttd.cn.gov.cn.xmttd.cn
http://www.morning.lfjmp.cn.gov.cn.lfjmp.cn
http://www.tj-hxxt.cn/news/237754.html

相关文章:

  • 长春企业网站设计注册一家公司要花多少钱
  • dede网站如何换logo公司网站.可以自己做吗
  • 商城网站建设怎么建设珠海做网站公司有哪些
  • 做卡贴和果冻贴的网站公司网站对比那几点优势
  • 门户网站首页模板下载wordpress 图片轮播
  • 怎样建淘宝客网站网站建设平台排行榜
  • 手机如何制作网站源码外文网站建设
  • 常德天恒建设网站手表价格网站
  • 如何对网站做实证分析免费刷推广链接的网站
  • net网站开发参考文献专做国际时事评论网站
  • 做网站怎么云存储oppo游戏中心官网
  • 网站建设公司的前景查公司名称是否已经被注册
  • 无锡网站关键词优化h5企业网站源码
  • 西宁网站建设优化案例西安商城网站建设制作
  • 网站 攻击 刷流量广州市筑正工程建设有限公司网站
  • 网站建设收费标准如何房产咨询律师免费咨询
  • 华企立方网站企业为什么要管理
  • 公司做手机网站建设网站301跳转
  • 宿迁网站建设案例那个网站做外贸好
  • 网站建设摊销几年数据分析师培训机构
  • 建设网站团队深圳家装网站建设多少钱
  • phpcms 视频网站模板用ps做网站页面的大小
  • 个人网站相册怎么做铭讯网站建设
  • 做网站程序看什么书北京网络教育
  • 上海网站开发外包织梦大气绿色大气农业能源化工机械产品企业网站源码模版
  • 现在网站如何做优化微分销商城系统
  • 上海 做网站网站工信部实名认证中心
  • 不懂代码怎么做网站基于jsp的网站开发的文献
  • 做企业网站用什么程序企业如何申请网站
  • 做网站时图片的分辨率是多少百度搜索页