MFC中list列表标头的问题

作者&投稿:巴安 (若有异议请与网页底部的电邮联系)
MFC中list control的表头该如何设置,那些语句应该加在哪个函数里?~

table_widget->setColumnCount(4); //设置列数
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:transparent; height:10px;}"
"QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
"QScrollBar::handle:hover{background:gray;}"
"QScrollBar::sub-line{background:transparent;}"
"QScrollBar::add-line{background:transparent;}");
table_widget->verticalScrollBar()->setStyleSheet("QScrollBar{background:transparent; width: 10px;}"
"QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
"QScrollBar::handle:hover{background:gray;}"
"QScrollBar::sub-line{background:transparent;}"
"QScrollBar::add-line{background:transparent;}");

点击表头对数据进行排序是很常见的功能,这里给出MFC的简单实现。//函数功能:响应点击列表框上的表头动作,对列表中的数据进行排序void CStudManageDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // TODO: Add your control notification handler code here m_SortColumn = pNMListView->iSubItem; m_bAsc=!m_bAsc;//升序还是降序 int count = m_list01.GetItemCount(); //行数 for(int i=0; iGetItemText(lParam1,m_SortColumn); CString strItem2 = pListCtrl->GetItemText(lParam2,m_SortColumn); if (m_bAsc) { return strcmp(strItem2, strItem1); } else { return strcmp(strItem1, strItem2); }}这里有一点需要注意的地方,m_bAsc和m_SortColumn必须声明为static变量,在类外初始化。MyCompareProc也要声明为static CALLBACK函数。

HDITEM
Contains information about an item in a header control. This structure supersedes the HD_ITEM structure.
HDITEM是M$定义的结构体类型 用来描述 header control
typedef struct _HDITEM {
UINT mask;
int cxy;
LPTSTR pszText;
HBITMAP hbm;
int cchTextMax;
int fmt;
LPARAM lParam;
#if (_WIN32_IE >= 0x0300)
int iImage;
int iOrder;
#endif
#if (_WIN32_IE >= 0x0500)
UINT type;
LPVOID pvFilter;
#endif
} HDITEM, FAR * LPHDITEM;

Members
mask ---------- 结构体成员mask 由以下几个bit信息(位运算学过没? 你的那是 “按位或”)最合起来
Flags indicating which other structure members contain valid data or must be filled in. This member can be a combination of the following values: Flag Description
HDI_BITMAP The hbm member is valid.
HDI_FORMAT The fmt member is valid. ========fmt成员有效
HDI_FILTER Version 5.80. The type and pvFilter members are valid. This is used to filter out the values specified in the type member.
HDI_HEIGHT The cxy member is valid and specifies the item's height.
HDI_IMAGE Version 4.70. The iImage member is valid and specifies the image to be displayed with the item.
=====iImage成员有效
HDI_LPARAM The lParam member is valid.
HDI_ORDER Version 4.70. The iOrder member is valid and specifies the item's order value.
HDI_TEXT The pszText and cchTextMax members are valid.
HDI_WIDTH The cxy member is valid and specifies the item's width.

CHeaderCtrl::GetItem
BOOL GetItem( int nPos, HDITEM* pHeaderItem ) const; // 指针没学过么
pHeader->GetItem(m_ncol,&hdi); 取变量的地址没学过么

C基础语法之指针做函数的参数,实测是某个变量的地址 形参是指针变量,

fmt
Flags that specify the item's format. -------- 用来制定item的格式
Set one of the following flags to specify text justification:

Flag Description
HDF_CENTER The item's contents are centered. 居中
HDF_LEFT The item's contents are left-aligned. 左对齐
HDF_RIGHT The item's contents are right-aligned. 右对齐

Set one of the following flags to control the display:

Flag Description
HDF_BITMAP The item displays a bitmap. 显示位图
HDF_BITMAP_ON_RIGHT Version 4.70. The bitmap appears to the right of text. This does not affect an image from an image list assigned to the header item.
HDF_OWNERDRAW The header control's owner draws the item.
HDF_STRING The item displays a string.

The preceding value can be combined with:

Flag Description
HDF_IMAGE Version 4.70. Display an image from an image list. Specify the image list by sending an HDM_SETIMAGELIST message. Specify the index of the image in the iImage member of this structure.
HDF_JUSTIFYMASK Isolate the bits corresponding to the three justification flags listed in the preceding table.
HDF_RTLREADING Typically, windows display text left-to-right (LTR). Windows can be mirrored to display languages such as Hebrew or Arabic that read right-to-left (RTL). Usually, header text is read in the same direction as the the text in its parent window. If HDF_RTLREADING is set, header text will read in the opposite direction from the text in the parent window.


口袋妖怪:红,蓝宝石金手指
在VBA中选cheat-->cheat list-->Code... 第1个物品 020259f4:??? 第2个物品 020259f8:??? 020259f6:0063 020259fA:0063 第3个物品 020259fC:??? 第4个物品 02025A00:??? 020259fE:0063 02025A02:0063 第5个物品 02025A04:??? 第6个物品 02025A08:??? 02025A06:0063...

介绍几个下载FC游戏的网站
国治模拟精品屋 http:\/\/www.emu618.com\/GamesSort_36.aspx

Docker 镜像中安装mkfontscale、mkfontdir、fc-cache
 1、执行下面的命令,编辑系统资源库列表:              vi \/etc\/apt\/sources.list  2、修改为以下内容(原来的内容可以注释一下): 附:deb http:\/\/mirrors.aliyun.com\/ubuntu\/ bionic main restricted universe multiverse deb...

XP中的cmd怎么对比两个文件是否相同
对,就用FC比,很容易的。(千万别用for命令比,慢死!)在FC后面,加入两个文件名(绝对或相对路径都行)就可以了,如:fc a.txt b.txt如果要进行判断,可以写成以下格式:(fc c:\\a.txt f:\\test\\b.txt>nul) && (rem 文件相同 ) || (rem 文件不同)...

求口袋妖怪火红386版的 金手指
在VBA中选[Cheat]-[Cheat list]-[Gameshark] 把上面的代码复制粘贴到code的文本框内就可以了 PM放进饲养屋后,主角走动一步以上再拿回就会变成100级,不过此时PM的经验值最高位会变问号 ALT+C(修改)——C(已修改数据列表)——GAMESHARK(GAMESHARK作弊码)中输入以上代码。 飞去南岛 2256EF8A97D73776 947888ccE...

有谁记得一个FC红白机游戏,小孩做梦扔糖果
告诉你正确的名字吧——小尼莫 梦的大师,英文名为Little Nemo-The Dream Master,这是CAPCOM当年在FC上的名作。下载地址:ftp:\/\/free1:KnCbVKVE@ftp.99inet.com\/Roms&Games\/Console\/Nintendo%20Family%20Computer(FC,NES)\/Roms\/No-Intro\/Little%20Nemo%20-%20The%20Dream%20Master%20(E).zip...

求教关于DOS的问题?
(5)\/L 参数:将全部用小写字母对文件或子目录进行列表 训练: dir \/a 列当前目录所有文件(含隐含及系统文件) dir \/ah 列隐含文件(包含子目录(隐含的)...名, \/list 仅列出可恢复的文件,而不恢复 undelete \/load 将undelete装入内存 \/unload 将undelete卸出内存 \/s[drive]对指定驱动器进行监测管理 undelete\/...

linux字体安装与卸载
切换到root权限 将SimSun-ExtB.ttf 拷贝到 \/usr\/share\/fonts\/chinese 下  没有chinese目录可以mkdir新建一个 cd \/usr\/share\/fonts\/chinese sudo mkfontscale sudo mkfontdir sudo fc-cache 安装完毕 查看系统字体命令  fc-list 以下补充卸载过程 直接删除 chinese文件夹 执行 ...

DOS命令有常见的
1.功能:创建新的子目录2.类型:内部命令3.格式:MD[盘符:][路径名]〈子目录名〉4.使用说明:(1)...(五)FC——文件比较命令1.功能:比较文件的异同,并列出差异处。2.类型:外部命令3.格式:FC[盘符:]...3.格式:UNDELETE[盘符:][路径名]〈文件名〉[\/DOS]\/LIST][\/ALL]4.使用说明:使用UNDELETE可以使用...

DOS命令有哪些?
(5)\/L 参数:将全部用小写字母对文件或子目录进行列表 训练: dir \/a 列当前目录所有文件(含隐含及系统文件) dir \/ah 列隐含文件(包含子目录(隐含的)...应注意的是在windows中最好不要用它,因为windows本身有对扩展内存进行管理 的程序.应采用windows中的管理器. 十二、fc 命令 fc\/b dt.dat dt2.dat>b ...

南郊区13362665158: MFC中list列表标头的问题 -
除善天罗: HDITEM Contains information about an item in a header control. This structure supersedes the HD_ITEM structure.HDITEM是M$定义的结构体类型 用来描述 header control typedef struct _HDITEM { UINT mask;int cxy;LPTSTR pszText;HBITMAP...

南郊区13362665158: 如何为list control控件设置列表头 -
除善天罗: 新建工程,注意选择 MFC AppWizard(exe),并输入工程名在弹出的对话框中选择【基于对话框】,然后确定在对话框界面中,删除不需要的静态文本控件,并添加listcontrol列表控件 右击控件,在样式中选择【报告】右击列表控件,选择【...

南郊区13362665158: MFC中list control的表头该如何设置,那些语句应该加在哪个函数里? -
除善天罗: void RefreshListViewHeader(CListCtrl *pListCtrl,CStringArray m_arrHeaderLabel, long* col_wide_arr) {if(pListCtrl==NULL) return; int i, NUM_COLUMNS, nColumnCount; CHeaderCtrl *pHeader = pListCtrl->GetHeaderCtrl(); nColumnCount = ...

南郊区13362665158: 如何设置MFC列表控件的表头 -
除善天罗: 表头控件实现不了,须用代码: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("类...

南郊区13362665158: MFC列表控件CtrlList怎么隐藏行标题 -
除善天罗: 无列头ListCtrl.rar”0分 http://download.csdn.net/detail/schlafenhamster/4916144 “本程序 说明 如何 对 report 模式下 无 列头 的 ListCtrl 控制列的宽度”

南郊区13362665158: MFC中列表控件的DeleteAllItems()方法只能清空列表控件里显示的内容,不能清空第一行的列表的表头 -
除善天罗: 清空列表中的内容是DeleteAllItem();//以下是清空表头的是 CHeaderCtrl* pHeaderCtrl = m_list->GetHeaderCtrl(); if (pHeaderCtrl != NULL) { int nColumnCount = pHeaderCtrl->GetItemCount(); for (int i=0; i<nColumnCount; i++) { m_list->DeleteColumn(0); } }

南郊区13362665158: MFC 列表显示问题请教
除善天罗: listbox的话可以一行一行地插入,可以把数据一行一行读到一个CString s把s插入到列表中的语句是 c_list.AddString(s); 立即生效,不需要updatedata先把listbox的sort属性去掉,不然会自动排序 到时候删除类似的是c_list.DeleteString(i) i表示索引 从0开始 c_list是为listbox绑定的控制变量

南郊区13362665158: MFC建立列表框类向导问题 -
除善天罗: 你那个abc是全局函数,我想你应该是在对话框里面.应该建某个对话框类的成员函数 void C***Dlg::abc() { m_list.AddString(list); }

南郊区13362665158: MFC中List Control的问题
除善天罗: icon为小图标模式,类似你打开 我的电脑 C盘的图标浏览方式report为详细信息浏览方式,展示给用户的界面不同,但其实原数据是一样的

南郊区13362665158: MFC程序中遇到的一个关于CStringList的问题 -
除善天罗: 如果非要这样保存,两种方法:1、把每个list的指针保存,通过指针访问2、使用map,直接访问

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网