久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

QTableView 打印

QTableView printing(QTableView 打印)
本文介紹了QTableView 打印的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我是 QT 新手,我嘗試從 QTableView 打印出來

I am new on QT an I try to print out from QTableView

我該怎么做?

非常感謝

推薦答案

這是擺脫中間文件的第一個答案的變體.

Here is a variation of the first answer that gets rid of the intermediate file.

QString strStream;
QTextStream out(&strStream);

const int rowCount = pPublic->tableView->model()->rowCount();
const int columnCount = pPublic->tableView->model()->columnCount();

out <<  "<html>
"
    "<head>
"
    "<meta Content="Text/html; charset=Windows-1251">
"
    <<  QString("<title>%1</title>
").arg(strTitle)
    <<  "</head>
"
    "<body bgcolor=#ffffff link=#5000A0>
"
    "<table border=1 cellspacing=0 cellpadding=2>
";

// headers
out << "<thead><tr bgcolor=#f0f0f0>";
for (int column = 0; column < columnCount; column++)
    if (!pPublic->tableView->isColumnHidden(column))
        out << QString("<th>%1</th>").arg(pPublic->tableView->model()->headerData(column, Qt::Horizontal).toString());
out << "</tr></thead>
";

// data table
for (int row = 0; row < rowCount; row++) {
    out << "<tr>";
    for (int column = 0; column < columnCount; column++) {
        if (!pPublic->tableView->isColumnHidden(column)) {
            QString data = pPublic->tableView->model()->data(pPublic->tableView->model()->index(row, column)).toString().simplified();
            out << QString("<td bkcolor=0>%1</td>").arg((!data.isEmpty()) ? data : QString("&nbsp;"));
        }               
    }
    out << "</tr>
";
}
out <<  "</table>
"
    "</body>
"
    "</html>
";

QTextDocument *document = new QTextDocument();
document->setHtml(strStream);

QPrinter printer;

QPrintDialog *dialog = new QPrintDialog(&printer, NULL);
if (dialog->exec() == QDialog::Accepted) {
    document->print(&printer);
}

delete document;

這篇關(guān)于QTableView 打印的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 99综合在线| 欧美一级视频在线观看 | 欧美激情久久久 | 亚洲高清久久 | 夏同学福利网 | 日本不卡视频 | 国产精品福利视频 | 国产精品国产精品国产专区不蜜 | 特级丰满少妇一级aaaa爱毛片 | 国产欧美日韩在线一区 | 国内精品视频免费观看 | 欧美综合国产精品久久丁香 | 国产免费观看久久黄av片涩av | 色婷婷综合久久久中字幕精品久久 | 精品一二区 | aaaa网站 | 国产91久久久久 | 国产 欧美 日韩 一区 | 国产视频一区二区三区四区五区 | 91亚洲国产 | 在线日韩视频 | 粉嫩一区二区三区国产精品 | 成人在线视频网 | 成人午夜视频在线观看 | 天堂一区二区三区四区 | 国产成人99久久亚洲综合精品 | 日韩国产精品一区二区三区 | 精品国产一区二区三区久久影院 | 日韩在线中文字幕 | 亚洲精品v日韩精品 | 欧美一级在线视频 | 日韩中文一区 | 久久成人一区 | 国产一级在线 | 亚洲精品乱码久久久久久9色 | 日韩国产精品一区二区三区 | 国产三级大片 | 羞羞视频在线观看网站 | 亚洲欧美一区二区在线观看 | 美日韩中文字幕 | 一区二区三区四区在线免费观看 |