#include "widget.h"
#include <QApplication>
#include <QTableView>
#include <QHeaderView>
#include "tool.h"
#include "textdelegate.h"
int main( int argc, char *argv[])
{
QApplication app(argc, argv);
VIPModel *model = new VIPModel(5, 5);
QTableView *tableView = new QTableView;
//把表格的背景调成黄蓝相间
//这种方法是在网上看到的,用起来还真方便啊
tableView->setAlternatingRowColors( true );
tableView->setStyleSheet( "QTableView{background-color: rgb(250, 250, 115);"
"alternate-background-color: rgb(141, 163, 215);}" );
tableView->setWindowTitle( "VIP List" );
tableView->resize(700, 400);
tableView->setModel(model);
QStringList headerList;
headerList << "No." << "ID" << "Name" << "Age\n我的" << "Sex" << "Show\n单位1" << "Show2\n单位2" << "Show3\n单位3";
model->setHorizontalHeaderLabels(headerList);
tableView->verticalHeader()->setVisible( false );
tableView->horizontalHeader()->setStretchLastSection( true );
//为每一列加载委托
ReadOnlyDelegate readOnlyDelegate;
tableView->setItemDelegateForColumn(0, &readOnlyDelegate);
UserIDDelegate userIDDelegate;
tableView->setItemDelegateForColumn(1, &userIDDelegate);
AgeDelegate spinBoxDelegate;
tableView->setItemDelegateForColumn(3, &spinBoxDelegate);
SexDelegate comboBoxDelegate;
tableView->setItemDelegateForColumn(4, &comboBoxDelegate);
IconDelegate iconDelegate;
tableView->setItemDelegateForColumn(5, &iconDelegate);
WrapTextDelegate wrapTextDelegate;
tableView->setItemDelegateForColumn(6, &wrapTextDelegate);
TextDelegate textDelegate;
tableView->setItemDelegateForColumn(7, &textDelegate);
QString text = "sd ce 等等";
/*
QString strHTML = QString("<html> \
<head> \
<style> \
font{font-size:12px; color:blue;} #f{font-size:10px; color: green;} \
</style> \
</head> \
<body>\
<font>%1</font> \
<font>%2</font> \
</body> \
</html>").arg(text).arg(text);
*/
QString strHTML;
strHTML = QString("<style> font{font-size:12px; color:blue;} #f{font-size:10px; color: green;}</style><h1>font{font-size:12px; color:blue;} #f{font-size:10px; color: green;} ");
strHTML += QString("<h2><font color = red>Qt!</font></h2></h1>");
strHTML = QString("<html><head>font{font-size:12px; color:blue;} #f{font-size:10px; color: green;} </style> </head> <h1> <font color = red>Qt!</font><font color = blue>Qt!</font></h1><html>");
for ( int i=0; i<10; i++)
{
QModelIndex index = model->index(i, 0, QModelIndex());
model->setData(index, i);
index = model->index(i, 6, QModelIndex());
model->setData(index,"我哦我\n我12345678");
index = model->index(i, 7, QModelIndex());
model->setData(index,strHTML);
}
tableView->show();
return app.exec();
}
QTableView 标题换行显示和富文本显示 qt5.8
需积分: 36 161 浏览量
2018-12-24
23:18:52
上传
评论 1
收藏 9KB RAR 举报
jerk05
- 粉丝: 2
- 资源: 19
最新资源
- 三次样条插值的介绍-什么是三次样条插值原理
- http的一些相关介绍-对于我们来说什么是http
- 全卷积网络基于voc2012数据集简单pytorch实现
- pycharm的一些介绍-用于更好的学习python
- 基于C++的程序设计大赛天梯赛L2答案(天梯赛)
- 基于python实现的三次样条插值和均值插值法实现
- Python语言教程2-python批量图片大小处理-多文件夹
- Python语言教程1-python批量图片重命名,将后缀某几个不想要的字去除
- Space Combat Kit 太空战斗套件Unity游戏开发插件资源unitypackage C#
- Universal Device Preview 通用设备预览Unity游戏开发插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈