﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-再生的雄鹰学习、工作笔记-文章分类-QT</title><link>http://www.cppblog.com/reborntercel/category/18150.html</link><description>QT、C/C++</description><language>zh-cn</language><lastBuildDate>Wed, 16 Nov 2011 08:26:24 GMT</lastBuildDate><pubDate>Wed, 16 Nov 2011 08:26:24 GMT</pubDate><ttl>60</ttl><item><title>QT:给QTableWidget组件设置水平标题</title><link>http://www.cppblog.com/reborntercel/articles/160266.html</link><dc:creator>再生的雄鹰</dc:creator><author>再生的雄鹰</author><pubDate>Wed, 16 Nov 2011 07:49:00 GMT</pubDate><guid>http://www.cppblog.com/reborntercel/articles/160266.html</guid><wfw:comment>http://www.cppblog.com/reborntercel/comments/160266.html</wfw:comment><comments>http://www.cppblog.com/reborntercel/articles/160266.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/reborntercel/comments/commentRss/160266.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/reborntercel/services/trackbacks/160266.html</trackback:ping><description><![CDATA[第一种:使用QStringList方式 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">QString&nbsp;labels;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />labels&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;QObject::tr(</span><span style="color: #000000">"</span><span style="color: #000000">姓名</span><span style="color: #000000">"</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;QObject::tr(</span><span style="color: #000000">"</span><span style="color: #000000">性别</span><span style="color: #000000">"</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;QObject::tr(</span><span style="color: #000000">"</span><span style="color: #000000">身高</span><span style="color: #000000">"</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;QObject::tr(</span><span style="color: #000000">"</span><span style="color: #000000">年龄</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;&nbsp;<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />table.setHorizontalHeaderLabels(labels);</span></div><br />第二种:在自定义模型中，实现headerData() 
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">QVariant&nbsp;MyModel::headerData(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;section,&nbsp;Qt::Orientation&nbsp;orientation,&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;role)&nbsp;</span><span style="color: #0000ff">const</span><span style="color: #000000"><br /><img id="Codehighlighter1_91_290_Open_Image" onclick="this.style.display='none'; Codehighlighter1_91_290_Open_Text.style.display='none'; Codehighlighter1_91_290_Closed_Image.style.display='inline'; Codehighlighter1_91_290_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="width: 11px; display: none; height: 16px" id="Codehighlighter1_91_290_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_91_290_Closed_Text.style.display='none'; Codehighlighter1_91_290_Open_Image.style.display='inline'; Codehighlighter1_91_290_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_91_290_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_91_290_Open_Text"><span style="color: #000000">{<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(role&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;Qt::DisplayRole&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;orientation&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;Qt::Horizontal)<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;header[section];&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;header为QStringList,用户自定义</span><span style="color: #008000"><br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;QAbstractTableModel::headerData(section,&nbsp;orientation,&nbsp;role);<br /><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div><br /><img src ="http://www.cppblog.com/reborntercel/aggbug/160266.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/reborntercel/" target="_blank">再生的雄鹰</a> 2011-11-16 15:49 <a href="http://www.cppblog.com/reborntercel/articles/160266.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>