table_widget->horizontalHeader()->setDefaultSectionSize(150)
table_widget->horizontalHeader()->setClickable(false)//设置表头不可点击(默认点击后进行排序)
//设置表头内容
QStringList header
header<<tr("name")<<tr("last modify time")<<tr("type")<<tr("size")
table_widget->setHorizontalHeaderLabels(header)
//设置表头字体加粗
QFont font = this->horizontalHeader()->font()
font.setBold(true)
table_widget->horizontalHeader()->setFont(font)
table_widget->horizontalHeader()->setStretchLastSection(true)//设置充满表宽度
table_widget->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents)
table_widget->verticalHeader()->setDefaultSectionSize(10)//设置行高
table_widget->setFrameShape(QFrame::NoFrame)//设置无边框
table_widget->setShowGrid(false)//设置不显示格子线
table_widget->verticalHeader()->setVisible(false)//设置垂直头不可见
table_widget->setSelectionMode(QAbstractItemView::ExtendedSelection) //可多选(Ctrl、Shift、 Ctrl+A都可以)
table_widget->setSelectionBehavior(QAbstractItemView::SelectRows) //设置选择行为时每次选择一行
table_widget->setEditTriggers(QAbstractItemView::NoEditTriggers)//设置不可编辑
table_widget->horizontalHeader()->resizeSection(0,150)//设置表头第一列的宽度为150
table_widget->horizontalHeader()->setFixedHeight(25)//设置表头的高度
table_widget->setStyleSheet("selection-background-color:lightblue")//设置选中背景色
table_widget->horizontalHeader()->setStyleSheet("QHeaderView::section{background:skyblue}")//设置表头背景色
//设置水平、垂直滚动条样式
table_widget->horizontalScrollBar()->setStyleSheet("QScrollBar{background:transparentheight:10px}"
"QScrollBar::handle{background:lightgrayborder:2px solid transparentborder-radius:5px}"
"QScrollBar::handle:hover{background:gray}"
"QScrollBar::sub-line{background:transparent}"
"QScrollBar::add-line{background:transparent}")
table_widget->verticalScrollBar()->setStyleSheet("QScrollBar{background:transparentwidth: 10px}"
"QScrollBar::handle{background:lightgrayborder:2px solid transparentborder-radius:5px}"
"QScrollBar::handle:hover{background:gray}"
"QScrollBar::sub-line{background:transparent}"
"QScrollBar::add-line{background:transparent}")
表头控件实现不了,须用代码:m_List.InsertColumn(0,_T("编号"),LVCFMT_LEFT,40)
m_List.InsertColumn(1,_T("IP地址"),LVCFMT_LEFT,120)
m_List.InsertColumn(2,_T("端口"),LVCFMT_LEFT,60)
m_List.InsertColumn(3,_T("类型"),LVCFMT_LEFT,70)
m_List.InsertColumn(4,_T("地区"),LVCFMT_LEFT,200)
m_List.InsertColumn(5,_T("响应"),LVCFMT_LEFT,100)
m_List.InsertColumn(6,_T("验证时间"),LVCFMT_LEFT,150)
m_List.InsertColumn(7,_T("使用时间"),LVCFMT_LEFT,150)
m_List.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT)
m_List.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_GRIDLINES,LVS_EX_GRIDLINES)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)