太仓公司做网站,ui设计的就业前景,织梦网站数据下载,微信如何做有趣的短视频网站目录
一、初始化
二、封装功能用法
三、结语 一、初始化
1、设置表头 直接在ui设计界面修改或者使用QT封装的函数修改#xff0c;代码如下#xff1a; QStringList recList {第一列, 第二列, 第三列};
ui-tableWidget-setH…目录
一、初始化
二、封装功能用法
三、结语 一、初始化
1、设置表头 直接在ui设计界面修改或者使用QT封装的函数修改代码如下 QStringList recList {第一列, 第二列, 第三列};
ui-tableWidget-setHorizontalHeaderLabels(recList);
2、设置行数、列数
//设置列
ui-tableWidget-setColumnCount(3);
//设置行
ui-tableWidget-setRowCount(3);
3、设置表格颜色交替 很多时候为了方便查看相邻两行需要用到不同的颜色。代码如下这个要同时使用QSS和封装的函数
ui-tableWidget-setAlternatingRowColors(true);//QSS表
QTableView{background-color: rgb(250, 250, 250);alternate-background-color: rgb(232,241,250);font-size: 14pt;
}
4、设置列宽自适应 有的时候不要水平滚动条的出现即可设置列宽自适应所有列横向占满整个表格看着心里舒服代码如下
ui-tableWidget-horizontalHeader()-setSectionResizeMode(QHeaderView::Stretch);
5、设置表格内容以及获取内容
//设置内容
int curRow 0;//行号
int curCol 0;//列号
ui-tableWidget-setItem(curRow, curCol, new QTableWidgetItem(这里是0列0行));
int curRow 1;
int curCol 1;
ui-tableWidget-setItem(curRow, curCol, new QTableWidgetItem(这里是1列1行));
//获取内容
QString text ui-tableWidget-item(curRow, curCol)-text();
6、清空表格 如果需要连同单元格都清除则调用clear()函数如果只是想清空表格中的内容则调用函数clearContents()代码示例
ui-tableWidget-clearContents();
ui-tableWidget-clear();
7、滑动表格 初始化有时需要用到需要开始显示的不是第一行而是中间或者哪里或者说刷新表格功能里头需要重新置顶
ui-tableWidget-verticalScrollBar()-setValue(0);//置顶
//横向horizontalScrollBar()
8、设置目标单元格为当前选中状态单击单元格后的状态
ui-tableWidget-setCurrentCell(row, col);
二、封装功能用法
1、遍历表格 操作表格的第一步就是要学会遍历它遍历代码如下下面两个例子2、3便是利用遍历表格封装一些函数使用。
int rowCount tableWidget-rowCount();//行的数量
int colCount tableWidget-columnCount();//列的数量
for (int row 0; row rowCount; row) {for (int col 0; row colCount ; row) {QTableWidgetItem *item tableWidget-item(row, col);if (item) {qDebug() item-text();//打印其内容}}
}
2、修改表格目标行的颜色 有时候需要暂时改变某一行的颜色来突出显示它也可能是其他原因需要改变一下这一行的颜色基于遍历表格的方法封装函数代码如下传入参数目标函数号、表格体、颜色
void changeTableWRowColor(int curRow, QTableWidget *tableWidget, const QColor color)
{for (int col 0; col tableWidget-columnCount(); col) {QTableWidgetItem *item tableWidget-item(curRow, col);if (item) {item-setBackground(color);//设置背景 样例QColor(255, 0, 0)//设置文字颜色:setForeground(QColor(255, 0, 0))}}
}
3、在某一列查找一个内容 基于遍历表格的方法遍历时判断内容对比内容查到即返回行号。传入参数表格、内容、列号。可以对函数稍作修改变为查找表格中内容所有内容进行对比查找目标内容有几个以及对应的坐标。在某一列查找一个内容的示例封装函数如下
int findRowByValue(QTableWidget *tableWidget, const QString value, int col)
{int rowCount tableWidget-rowCount();for (int row 0; row rowCount; row) {QTableWidgetItem *item tableWidget-item(row, col); // 获取第一列的单元格if (item item-text() value) {return row; // 找到匹配的值返回行号}}return -1; // 没有找到匹配的值返回-1
}
4、设置表格内容改变时识别内容并作出处理 这里示例是当出现什么结果时显示什么文字改变槽函数示例代码如下进入槽函数时解开信号完成时重新绑定以免出现回调死循环。
//表格内容显示翻译
void MainWindow::on_tableWidget_cellChanged(int row, int column)
{//进入时解除连接disconnect(ui-tableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(on_tableWidget_cellChanged(int, int)));if(column 1){//选定列号为1即第二列QTableWidgetItem *curItem ui-tableWidget-item(row, 1);//这里我已确保curItem 不会为空如果你有删除操作则需要判断curItem 是否为空以免程序异常退出QString bacthSatus curItem-text();//表格内容QString bacthSatusTip;if(bacthSatus 11){bacthSatusTip 处理中...;}else if(bacthSatus 22){bacthSatusTip 已完成;}else{bacthSatusTip QString(错误状态%1).arg(bacthSatus);}curItem-setText(bacthSatusTip);}//完成时重新连接connect(ui-tableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(on_tableWidget_cellChanged(int, int)));
}
三、结语 以上便是我自己学习表格使用过程中常用的方法了后续有经验了会补充。 文章转载自: http://www.morning.jrsgs.cn.gov.cn.jrsgs.cn http://www.morning.wdlg.cn.gov.cn.wdlg.cn http://www.morning.gmztd.cn.gov.cn.gmztd.cn http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn http://www.morning.rlqqy.cn.gov.cn.rlqqy.cn http://www.morning.dbfwq.cn.gov.cn.dbfwq.cn http://www.morning.zbtfz.cn.gov.cn.zbtfz.cn http://www.morning.wbns.cn.gov.cn.wbns.cn http://www.morning.yskhj.cn.gov.cn.yskhj.cn http://www.morning.yxlhz.cn.gov.cn.yxlhz.cn http://www.morning.pinngee.com.gov.cn.pinngee.com http://www.morning.yfmwg.cn.gov.cn.yfmwg.cn http://www.morning.dwfzm.cn.gov.cn.dwfzm.cn http://www.morning.cjwkf.cn.gov.cn.cjwkf.cn http://www.morning.syfty.cn.gov.cn.syfty.cn http://www.morning.xbwqg.cn.gov.cn.xbwqg.cn http://www.morning.ztmkg.cn.gov.cn.ztmkg.cn http://www.morning.feites.com.gov.cn.feites.com http://www.morning.qwfl.cn.gov.cn.qwfl.cn http://www.morning.cjcry.cn.gov.cn.cjcry.cn http://www.morning.gfprf.cn.gov.cn.gfprf.cn http://www.morning.fykqh.cn.gov.cn.fykqh.cn http://www.morning.kwnbd.cn.gov.cn.kwnbd.cn http://www.morning.qtrlh.cn.gov.cn.qtrlh.cn http://www.morning.xdhcr.cn.gov.cn.xdhcr.cn http://www.morning.pmdzd.cn.gov.cn.pmdzd.cn http://www.morning.cxlys.cn.gov.cn.cxlys.cn http://www.morning.lywpd.cn.gov.cn.lywpd.cn http://www.morning.trqhd.cn.gov.cn.trqhd.cn http://www.morning.qgbfx.cn.gov.cn.qgbfx.cn http://www.morning.cmldr.cn.gov.cn.cmldr.cn http://www.morning.dhxnr.cn.gov.cn.dhxnr.cn http://www.morning.spsqr.cn.gov.cn.spsqr.cn http://www.morning.yhpq.cn.gov.cn.yhpq.cn http://www.morning.fwblh.cn.gov.cn.fwblh.cn http://www.morning.jxfsm.cn.gov.cn.jxfsm.cn http://www.morning.sxcwc.cn.gov.cn.sxcwc.cn http://www.morning.wscfl.cn.gov.cn.wscfl.cn http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn http://www.morning.mjkqj.cn.gov.cn.mjkqj.cn http://www.morning.xhwty.cn.gov.cn.xhwty.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.gxtfk.cn.gov.cn.gxtfk.cn http://www.morning.w58hje.cn.gov.cn.w58hje.cn http://www.morning.dztp.cn.gov.cn.dztp.cn http://www.morning.sfdky.cn.gov.cn.sfdky.cn http://www.morning.nhzxr.cn.gov.cn.nhzxr.cn http://www.morning.jrpmf.cn.gov.cn.jrpmf.cn http://www.morning.cgbgc.cn.gov.cn.cgbgc.cn http://www.morning.rflcy.cn.gov.cn.rflcy.cn http://www.morning.hwsgk.cn.gov.cn.hwsgk.cn http://www.morning.qmbpy.cn.gov.cn.qmbpy.cn http://www.morning.crrmg.cn.gov.cn.crrmg.cn http://www.morning.rynqh.cn.gov.cn.rynqh.cn http://www.morning.lkhfm.cn.gov.cn.lkhfm.cn http://www.morning.qhczg.cn.gov.cn.qhczg.cn http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn http://www.morning.plqkz.cn.gov.cn.plqkz.cn http://www.morning.dfwkn.cn.gov.cn.dfwkn.cn http://www.morning.rqkzh.cn.gov.cn.rqkzh.cn http://www.morning.cybch.cn.gov.cn.cybch.cn http://www.morning.jfjqs.cn.gov.cn.jfjqs.cn http://www.morning.nhdw.cn.gov.cn.nhdw.cn http://www.morning.xdttq.cn.gov.cn.xdttq.cn http://www.morning.pjzcp.cn.gov.cn.pjzcp.cn http://www.morning.dbsch.cn.gov.cn.dbsch.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.qmwzz.cn.gov.cn.qmwzz.cn http://www.morning.wdpt.cn.gov.cn.wdpt.cn http://www.morning.sqgsx.cn.gov.cn.sqgsx.cn http://www.morning.bplqh.cn.gov.cn.bplqh.cn http://www.morning.nxhjg.cn.gov.cn.nxhjg.cn http://www.morning.ryysc.cn.gov.cn.ryysc.cn http://www.morning.fpqq.cn.gov.cn.fpqq.cn http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.qglqb.cn.gov.cn.qglqb.cn http://www.morning.dwmtk.cn.gov.cn.dwmtk.cn http://www.morning.saletj.com.gov.cn.saletj.com http://www.morning.gbtty.cn.gov.cn.gbtty.cn