QTableView 二次整理
一、设置可视化的组件
参考:
http://www.cnblogs.com/ribavnu/p/4810412.html
二、常用基本属性
http://www.cnblogs.com/ribavnu/p/4791393.html
三、编辑后提示是否保存
http://www.cnblogs.com/ribavnu/p/4702532.html
四、设置特定列是否能编辑
#
# C_TableView
# 在QTreeView基础上增加限制 特定列是否 可以编辑
#
class C_TableView(QTableView):
def __init__(self, parent=None):
QTableView.__init__(self, parent)
# 设置可以编辑的 列
# column:list
self.c_allow_edit = list()
#
# 设置可以编辑的 列
# allow_edit :list,
# value : 可以编辑的多个列, 列编号从0开始
def c_setAllowEdit(self, allow_edit):
self.c_allow_edit = allow_edit def edit(self, index, trigger, event): args = [index, trigger, event]
columnIndex = index.column() if event is not None:
# 2:鼠标的按下,3:鼠标的释放
# 4:鼠标的双击
# 如果 列 是否可以编辑
event_type = event.type()
if event_type ==4:
if columnIndex not in self.c_allow_edit :
return False return_value =super(QTableView, self) .edit( *args)
return return_value
五、设置特定列的代理,对 一 的 补充。
void QAbstractItemView::setItemDelegateForRow(int row, QAbstractItemDelegate *delegate)
# 自定义复选框checkbox
class Delegate_CheckBox(QtWidgets.QStyledItemDelegate): def createEditor(self, parent, option, index): editor = QtWidgets.QCheckBox('是', parent)
# 填充背景
#editor.setAutoFillBackground(True)
#editor.setGeometry(self.checkBoxRect(option)) return editor # 计算 check_box的位置 和 大小
def checkBoxRect(self, option): but_style = QtWidgets.QStyleOptionButton()
check_box_rect =QtWidgets. QApplication.style().subElementRect(
QtWidgets.QStyle.SE_CheckBoxIndicator,
but_style) check_box_point = QtCore.QPoint(option.rect.x() +
option.rect.width() / 2 -
check_box_rect.width() / 2,
option.rect.y() +
option.rect.height() / 2 -
check_box_rect.height() / 2);
return QtCore.QRect(check_box_point, check_box_rect.size()) def paint(self, painter, option, index): from PyQt5.QtWidgets import QStyle # 如果选中则高亮
if option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight()) #获取值
checked = index.model().data(index, QtCore.Qt.DisplayRole)
checked = int(checked)
#按钮的风格选项
checkBoxOption = QtWidgets.QStyleOptionButton()
checkBoxOption.state |= QtWidgets.QStyle.State_Enabled;
#根据值判断是否选中
if checked > 0 :
checkBoxOption.state |= QtWidgets.QStyle.State_On
else :
checkBoxOption.state |= QtWidgets.QStyle.State_Off #返回QCheckBox几何形状
checkBoxOption.rect = self.checkBoxRect(option)
#绘制QCheckBox
QtWidgets.QApplication.style().drawControl(QtWidgets.QStyle.CE_CheckBox,checkBoxOption,painter) def setEditorData(self, spinBox, index): data = index.data()
data = int(data)
if data > 0:
spinBox.setChecked(True)
else:
spinBox.setChecked(False) def setModelData(self, spinBox, model, index): data = spinBox.isChecked()
if data:
model.setData(index, 1)
else:
model.setData(index, 0) def updateEditorGeometry(self, editor, option, index):
# 原始的就这么一句话
#editor.setGeometry(option.rect) # 居中显示
rect = option.rect
option_x= rect.x()
option_y = rect.y()
option_width = rect.width()
# 微调下左边,误差原因不明
rect.moveTo(option_x + option_width /2 - 8 , option_y)
editor.setGeometry(rect)
六、
设置tableview背景透明
from PyQt5.QtGui import QPalette, QBrush, QColor
palette = tableView.palette()
palette.setBrush(QPalette.Base,QBrush(QColor(255,255,255,0)))
tableView.setPalette(palette)
QTableView 二次整理的更多相关文章
- 函数基础(二)(day11整理)
目录 昨日内容 函数的定义 函数的三种定义方式 空函数 有参函数 无参函数 函数的调用 函数的返回值 函数的参数 形参 实参 今日内容 可变长参数 可变长形参 可变长实参(仅作了解) 函数对象 函数嵌 ...
- xfs磁盘(文件)碎片查看和整理
网上有些帖子说XFS不用做碎片整理,其实是错误的.XFS用延迟写入等技术确实可以减少碎片的出现,但是如果服务器用了几年,并且文件操作比较频繁,还是会出现碎片的,应该整理.注意:在Debian中XFS相 ...
- Excel表3级数据整理工具
前言 做专题经常会遇到做数据级联的需求,大部分需求都长一个模样.销售给你一个excel表,然后你做一个省市经销商的级联.不知道以前大家是怎么样做的,我之前是把excel复制到sublime中,然后使用 ...
- 重新整理 .net core 实践篇—————日志系统之结构化[十八]
前言 什么是结构化呢? 结构化,就是将原本没有规律的东西进行有规律话. 就比如我们学习数据结构,需要学习排序然后又要学习查询,说白了这就是一套,没有排序,谈如何查询是没有意义的,因为查询算法就是根据某 ...
- RocketMQ架构原理解析(二):消息存储
一.概述 由前文可知,RocketMQ有几个非常重要的概念: broker 服务端,负责存储.收发消息 producer 客户端1,负责产生消息 consumer 客服端2,负责消费消息 既然是消息队 ...
- delphi控件属性大全-详解-简介
http://blog.csdn.net/u011096030/article/details/18716713 button 组件: CAPTION 属性 :用于在按钮上显示文本内容 Cancel ...
- Java 之 I/O 系列 01 ——基础
Java 之 I/O 系列 目录 Java 之 I/O 系列 01 ——基础 Java 之 I/O 系列 02 ——序列化(一) Java 之 I/O 系列 02 ——序列化(二) 整理<疯狂j ...
- Hadoop经典面试题(转)
单项选择题 1. 下面哪个程序负责 HDFS 数据存储. a)NameNode b)Jobtracker c)Datanode d)secondaryNameNode e)tasktracker 2. ...
- 2.JAVA垃圾回收机制
前言 线程独享的内存区域有程序计数器,虚拟机栈,本地方法栈,这些区域不用考虑内存回收的问题,随着线程的执行结束,自然就回收了,而堆内存和方法区的回收则不一样,他们的内存分配和回收是动态的. 1.对象存 ...
随机推荐
- BZOJ.2741.[FOTILE模拟赛]L(分块 可持久化Trie)
题目链接 首先记\(sum\)为前缀异或和,那么区间\(s[l,r]=sum[l-1]^{\wedge}sum[r]\).即一个区间异或和可以转为求两个数的异或和. 那么对\([l,r]\)的询问即求 ...
- CSDN博客文章的备份及导出电子书CHM
需要用到的工具集合下载:http://download.csdn.net/source/2881423 在CSDN.百度等写博客文章的应该很多,很多时候担心服务器有一天突然挂了,或者担心自己的号被封了 ...
- bzoj 1076 状态压缩最优期望
题意: 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随 机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后也不能再 ...
- Mybatis 中遍历map 参数中的 list 和 array 属性
原文:https://blog.csdn.net/liudongdong0909/article/details/51048835 问题在项目有中遇到批量删除操作时,需要根据两个属性去删除数据,其中一 ...
- 在ASP.NET Core2.0中使用百度在线编辑器UEditor(转)
一.起因 UEditor是百度旗下的富文本编辑器,对于后端上传处理仅提供了Asp.Net 版的支持. 如果想在.Net Core项目中使用,那么后台上传接口需要重构. UEditorNetCore:百 ...
- 浅谈压缩感知(十九):MP、OMP与施密特正交化
关于MP.OMP的相关算法与收敛证明,可以参考:http://www.cnblogs.com/AndyJee/p/5047174.html,这里仅简单陈述算法流程及二者的不同之处. 主要内容: MP的 ...
- linux 使用ifstat查看网络使用情况
首先安装ifstat wget http://distfiles.macports.org/ifstat/ifstat-1.1.tar.gz tar xzvf ifstat-1.1.tar.gz cd ...
- C# System.Collections.ArrayList
using System; using System.Collections; public class SamplesArrayList { public static void Main() { ...
- 【PMP】挣值分析
挣值分析(EVA):将实际进度和成本绩效与绩效测量基准进行比较. 1.名词解释 1.1 三个指标 PV [Plan value] 计划价值 官方释义:为计划工作分配的经批准的预算,它是为完成某活动或 ...
- 获取代理电脑的https证书方法
1.打开fiddler,tools->fiddler options 勾选check for certificate revocation 2.手机打开浏览器 输入fiddler所在电脑ip及端 ...