generate html code from QTableWidget with row and column span support
来源:互联网 发布:mac book 手写便签 编辑:程序博客网 时间:2024/06/07 00:33
#include <QApplication>
#include <zftpclient.h>
#include <zpdfviewer.h>
#include <QTableWidget>
#include <QHash>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget tTable;
tTable.setColumnCount(10);
tTable.setRowCount(20);
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QTableWidgetItem *tItem=new QTableWidgetItem;
tTable.setItem(i,j,tItem);
}
}
tTable.setSpan(0,0,1,3);
tTable.item(0,0)->setText("(Left,Top)");
tTable.setSpan(2,2,3,2);
tTable.item(2,2)->setText("This is beijing hour,open the door to the world.Join us ,couldn't you?");
tTable.setSpan(13,5,3,6);
tTable.item(13,5)->setText("hello,this is a html test page ,used to test subtitle parse server.is it work correct?");
tTable.show();
#if 0
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
qDebug()<<"("<<i<<","<<j<<"):"<<tTable.rowSpan(i,j)<<tTable.columnSpan(i,j);
}
}
qDebug()<<"ends...................";
#endif
//find out the invalid cells.
QList<QString> tInvalidCellsList;
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
if(tRowSpan>1 || tColSpan>1)
{
for(qint32 m=i;m<i+tRowSpan;m++)
{
for(qint32 n=j;n<j+tColSpan;n++)
{
if(m==i && n==j)
{
//bypass myself.
continue;
}
QString tKey=QString("%1,%2").arg(m).arg(n);
tInvalidCellsList.append(tKey);
}
}
}
}
}
//generate html.
qreal tColWidth=100.0/tTable.columnCount();
QString tHtml;
tHtml.append("<html>");
tHtml.append(QString("<head><style type=\"text/css\">body{font-size:12px;}table td{width:%1%;height:50px}table tr td{word-break:break-all;}</style></head>").arg(tColWidth));
tHtml.append("<body>");
tHtml.append("<table width=\"100%\" height=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">");
tHtml.append("\n");
for(qint32 i=0;i<tTable.rowCount();i++)
{
tHtml.append(QString("<tr>"));
tHtml.append("\n");
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
//bypass invalid cells.
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
tHtml.append(QString("<td rowspan=\"%1\" colspan=\"%2\" align=\"left\">").arg(tRowSpan).arg(tColSpan));
tHtml.append("<input type=\"checkbox\" checked=\"checked\">");
tHtml.append(tTable.item(i,j)->text());
tHtml.append("</td>");
tHtml.append("\n");
}
tHtml.append(QString("</tr>"));
tHtml.append("\n");
}
tHtml.append("</table>");
tHtml.append("\n");
tHtml.append("</body>");
tHtml.append("</html>");
QFile tFile("/home/shell.albert/subtitle.html");
if(tFile.open(QIODevice::WriteOnly))
{
tFile.write(tHtml.toUtf8());
tFile.flush();
tFile.close();
}
return 0;
return a.exec();
}
#include <zftpclient.h>
#include <zpdfviewer.h>
#include <QTableWidget>
#include <QHash>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget tTable;
tTable.setColumnCount(10);
tTable.setRowCount(20);
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QTableWidgetItem *tItem=new QTableWidgetItem;
tTable.setItem(i,j,tItem);
}
}
tTable.setSpan(0,0,1,3);
tTable.item(0,0)->setText("(Left,Top)");
tTable.setSpan(2,2,3,2);
tTable.item(2,2)->setText("This is beijing hour,open the door to the world.Join us ,couldn't you?");
tTable.setSpan(13,5,3,6);
tTable.item(13,5)->setText("hello,this is a html test page ,used to test subtitle parse server.is it work correct?");
tTable.show();
#if 0
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
qDebug()<<"("<<i<<","<<j<<"):"<<tTable.rowSpan(i,j)<<tTable.columnSpan(i,j);
}
}
qDebug()<<"ends...................";
#endif
//find out the invalid cells.
QList<QString> tInvalidCellsList;
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
if(tRowSpan>1 || tColSpan>1)
{
for(qint32 m=i;m<i+tRowSpan;m++)
{
for(qint32 n=j;n<j+tColSpan;n++)
{
if(m==i && n==j)
{
//bypass myself.
continue;
}
QString tKey=QString("%1,%2").arg(m).arg(n);
tInvalidCellsList.append(tKey);
}
}
}
}
}
//generate html.
qreal tColWidth=100.0/tTable.columnCount();
QString tHtml;
tHtml.append("<html>");
tHtml.append(QString("<head><style type=\"text/css\">body{font-size:12px;}table td{width:%1%;height:50px}table tr td{word-break:break-all;}</style></head>").arg(tColWidth));
tHtml.append("<body>");
tHtml.append("<table width=\"100%\" height=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">");
tHtml.append("\n");
for(qint32 i=0;i<tTable.rowCount();i++)
{
tHtml.append(QString("<tr>"));
tHtml.append("\n");
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
//bypass invalid cells.
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
tHtml.append(QString("<td rowspan=\"%1\" colspan=\"%2\" align=\"left\">").arg(tRowSpan).arg(tColSpan));
tHtml.append("<input type=\"checkbox\" checked=\"checked\">");
tHtml.append(tTable.item(i,j)->text());
tHtml.append("</td>");
tHtml.append("\n");
}
tHtml.append(QString("</tr>"));
tHtml.append("\n");
}
tHtml.append("</table>");
tHtml.append("\n");
tHtml.append("</body>");
tHtml.append("</html>");
QFile tFile("/home/shell.albert/subtitle.html");
if(tFile.open(QIODevice::WriteOnly))
{
tFile.write(tHtml.toUtf8());
tFile.flush();
tFile.close();
}
return 0;
return a.exec();
}
0 0
- generate html code from QTableWidget with row and column span support
- row span with XWPFTable
- Generate PDF from HTML
- [Twitter] Given a matrix with all elements sorted on each individual row and column find
- Attempted to generate class with no column
- Generate PDF from Batch Class and schedule class and send email notification with Pdf attachment
- codechef Row and Column Operations 题解
- boost sparse matrix row and column
- Set row and column to 1's
- jquey delegate add delete row and column
- Column AND Row Posted by David Dobrin
- div and span in HTML and CSS
- Generate .lib from .dll and .def
- Build OpenCV from source with CUDA support
- XHtmlTree - Tree control with support for HTML, XML, Smart Checkboxes, and Drag & Drop
- numpy : the difference between row and column vector
- Serving less HTML code starting from .NET 4.0 with ClientIDMode property
- "_OBJC_CLASS_$_WKWebView", referenced from:"...and "linker command failed with exit code 1 (use -v "
- Gps坐标转换成 百度坐标 高德坐标
- activity启动FLAG之FLAG_ACTIVITY_CLEAR_TASK
- ps把图片背景变透明
- 蛇形(回形)矩阵
- c2d libgdx 封装
- generate html code from QTableWidget with row and column span support
- itunes里面的设备栏里没应用程序选项
- LeetCode Add Binary (JavaScript)
- Oracle replace 函数用法 alisa问题记录1
- Permission denied:Android导出shared_prefs中xml文件时出错
- jdk配置环境变量
- Android WebView从assets中加载html5页面,实现地理位置定位
- Android传感器概述(五)
- IE中居中,FF中出问题