当前位置:网站首页>1. Qtablewidget insert button, flexibly delete the line, and display the line number in one column
1. Qtablewidget insert button, flexibly delete the line, and display the line number in one column
2022-07-22 18:54:00 【Moon cave】
QTableWidget Insert button
ui->tableWidget->setIndexWidget(ui->tableWidget->index(row, "button"), button);
Flexibly delete this bank
lds_pushbutton *button = qobject_cast<lds_pushbutton *>(this->sender());
if(button == 0)
return;
QModelIndex index = ui->tableWidget->indexAt(button->pos());
if(!index.isValid())
return;
ui->tableWidget->removeRow(index.row());
A column shows the line number
Set the proxy for this column , The code is as follows
QStyleOptionViewItemV4 opt;
opt = option;
initStyleOption(&opt, index);
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
const QWidget *widget = option.widget;
#else
const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
const QWidget *widget = v3? v3->widget : 0;
#endif
QStyle *style = widget? widget->style() : QApplication::style();
if(opt.state & QStyle::State_Selected)
painter->setPen(opt.palette.brush(QPalette::HighlightedText).color());
else
painter->setPen(opt.palette.brush(QPalette::Text).color());
opt.text = QString::number(index.row() + 1);
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);
边栏推荐
- 数据优化的方式
- 1.创建函数的动态库,2.HOWTO Create and Deploy a Sample DLL using MinGW
- Summary 20220119
- App mobile End test [6] application (APK) package Management and Activity
- Leetcode 654. maximum binary tree
- 【QT源代码复用】模拟QCompleter的弹窗方式
- LeetCode 720. 词典中最长的单词
- Flink学习笔记(五)DataStream API
- Parameter index out of range (1 &gt; number of parameters, which is 0).
- PAT基础习题集7-26 单词长度(精简代码)
猜你喜欢
mysql主从复制
6-2-深度优先搜索 地下迷宫探索 (30分)
App mobile End test [6] application (APK) package Management and Activity
PCV, PIL, pilot installation
Summary 20220121
Important knowledge points of go language: string, UTF-8 encoding, Rune
App mobile terminal test [6] application program (APK) package management and activity
Flink学习笔记(四)Flink运行时架构
如何解决执行yum makecache命令过程中出现的错误
数据存储分区--范围分区,哈希分区,列表分区,性能调优必不可缺少的部分
随机推荐
实现各个微服务间限制IP访问 的三种方式
Bull column - blog summary
PAT乙级1020月饼(注意测点)
Summary 20220209
消息中间件
Summary 20220121
Flink学习笔记(七)处理函数
Go language learning: go language journey (III)
递归求简单交错幂级数的部分和 (15分)
Summary 20220118 (binary tree)
LeetCode: 184. 部门工资最高的员工
数据库出现乱码,求解决办法、思路?
PTA 习题8-8 判断回文字符串
How PHP prevents CSRF attacks
ECSHOP disable cache and close cache
win10sp1升到最新版本;QT5.9.6静态编译(network有效)
JSON序列化对象时,如何返回有空值的带属性名称json字符串?
When serializing JSON objects, how to return JSON strings with attribute names with null values?
LeetCode 720. 词典中最长的单词
MySQL statement execution order