</pre><div></div><p style="font-size:14px; line-height:1.5; margin:10px auto; padding-top:0px; padding-bottom:0px"><span style="margin:0px; padding:0px; font-size:15px; color:rgb(0,0,255)">(2)设置表格为选择整行</span></p><div class="cnblogs_code" style="font-size:12px!important; line-height:1.5; margin:5px 0px; padding:5px; background-color:rgb(245,245,245); border:1px solid rgb(204,204,204); overflow:auto; color:rgb(0,0,0); font-family:'Courier New'!important"><pre style="margin-top:0px; margin-bottom:0px; padding:0px; white-space:pre-wrap; word-wrap:break-word; font-family:'Courier New'!important"><span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">1</span> <span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">/*</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">设置表格为整行选中</span><span style="margin:0px; padding:0px; color:rgb(0,128,0); line-height:1.5!important">*/</span>
<span style="margin:0px; padding:0px; color:rgb(0,128,128); line-height:1.5!important">2</span> ui.qtablewidget->setSelectionBehavior(QAbstractItemView::SelectRows);
(3)设置单个选中和多个选中
单个选中意味着每次只可以选中一个单元格,多个就是相当于可以选择”一片“那种模式。
1 /*设置允许多个选中*/ 2 ui.qtablewidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
(4)表格表头的显示与隐藏
对于水平或垂直方向的表头,如果不想显示可以用以下方式进行(隐藏/显示)设置:
1 ui.qtablewidget->verticalHeader()->setVisible(true); 2 ui.qtablewidget->horizontalHeader()->setVisible(false);
(5)设置具体单元格中字体的对齐方式