- 10
- 0
- 约1.05万字
- 约 42页
- 2020-06-13 发布于浙江
- 举报
8.3 视图(View) indexAt()函数的具体内容。 由于本例未用到以下函数的功能,所以没有实现具体内容,但仍然要写出函数体的框架,代码如下: QRect HistogramView::visualRect(const QModelIndex index)const{} void HistogramView::scrollTo(const QModelIndex index,ScrollHint){} QModelIndex HistogramView::moveCursor(QAbstractItemView::CursorAction cursor Action, Qt::KeyboardModifiers modifiers){} int HistogramView::horizontalOffset()const{} int HistogramView::verticalOffset()const{} bool HistogramView::isIndexHidden(const QModelIndex index)const{} QRegion HistogramView::visualRegionForSelection(const QItemSelection selection)const{} 8.3 视图(View) itemRegion()函数的具体代码如下: QRegion HistogramView::itemRegion(QModelIndex index) { QRegion region; if (index.column() == 1) //男 region = MRegionList[index.row()]; if (index.column() == 2) //女 region = FRegionList[index.row()]; if (index.column() == 3) //退休 region = SRegionList[index.row()]; return region; } 8.3 视图(View) (4)在头文件“mainwindow.h”中添加代码如下: #include histogramview.h private: HistogramView *histogram; (5)在源文件“mainwindow.cpp”中添加代码,其中,setupView()函数的代码修改。 (6)运行结果如图8.4所示。 8.4 代理(Delegate) 【例】(难度中等) 利用Delegate设计表格中控件如图8.7所示。实例文件见光盘CH804。 8.4 代理(Delegate) 具体实现步骤如下。 (1)首先,加载表格数据,以便后面的操作。源文件“main.cpp”中的具体代码如下: (2)选择“构建”→“构建项目DateDelegate”菜单项,首先按照如图8.8所示的格式编辑本例所用的数据文件“test.txt”,保存在项目D:\Qt\CH8\CH804\ build- DateDelegate-Desktop_Qt_5_4_0_MinGW_32bit- Debug目录下,然后运行程序,结果如图8.7所示。 8.4 代理(Delegate) (3)在图8.7中,使用手动的方式实现对生日的录入编辑。下面使用日历编辑框QDateTimeEdit 控件实现对生日的编辑,用自定义的Delegate来实现。 (4)DateDelegate 继承自QItemDelegate类。头文件“datedelegate.h”中的具体代码如下: #include QItemDelegate class DateDelegate : public QItemDelegate { Q_OBJECT public: DateDelegate(QObject *parent = 0); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem option, const QModelIndex index) const; //(a) void setEditorData(QWidget *editor, const QModelIndex index) const; //(b) void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex index) co
您可能关注的文档
最近下载
- 河道整治工程施工质量创优计划的实施效果评估与改进策略.docx VIP
- 水利工程质量创优方案(3篇).docx VIP
- 110kv变电站的设计毕业设计(论文).docx VIP
- 华中师范大学《C++程序设计》2020-2021学年第一学期期末试卷.pdf VIP
- 电力系统仿真:电力系统暂态仿真all.docx VIP
- 电力系统暂态稳定性仿真研究毕业设计(论文).docx VIP
- 3 浮力——液面升降问题(原卷版).docx VIP
- 核心素养视域下的初中数学单元作业设计研究.docx VIP
- 纪念红军长征90周年演讲稿(2025年最新版).pptx VIP
- 2002-2012 十年北京卷高考语文试卷深度解析.pdf VIP
原创力文档

文档评论(0)