#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();
}