QHeaderView 禁用某些列排序和添加QCheckBox控件
来源:互联网 发布:慢走丝编程软件 编辑:程序博客网 时间:2024/06/06 17:22
QHeaderView禁用某些列的排序,则只需要重载mousePressEvent mouseReleaseEvent两个函数,在函数体内判断当前点击列是否为需要禁用的列,如果是则设置点击无效setSectionsClickable(false); 再调用QHeaderView::mousePressEvent(event);/QHeaderView::mouseReleaseEvent(event); 然后再setSectionsClickable(true);
代码如下:
void HanderView::mousePressEvent(QMouseEvent* event)
{
const int index = logicalIndexAt(event->pos());
if (0 <= m_forbinSortList.indexOf(index))
{
setSectionsClickable(false);
}
QHeaderView::mousePressEvent(event);
if (!sectionsClickable())
{
setSectionsClickable(true);
}
}
void HanderView::mouseReleaseEvent(QMouseEvent* event)
{
const int index = logicalIndexAt(event->pos());
if (0 <= m_forbinSortList.indexOf(index))
{
setSectionsClickable(false);
}
QHeaderView::mouseReleaseEvent(event);
if (!sectionsClickable())
{
setSectionsClickable(true);
}
}
添加QCheckBox:
HanderView::HanderView(Qt::Orientation orientation, QWidget *parent)
: QHeaderView(orientation, parent)
{
m_pCheckBox = new QCheckBox(this);
m_pCheckBox->setFixedSize(qRound(1.3 * m_pCheckBox->sizeHint().height()),
m_pCheckBox->sizeHint().height());
m_pCheckBox->setFocusPolicy(Qt::NoFocus);
}
void HanderView::paintSection(QPainter* painter, const QRect& rect, int logicalIndex) const
{
if (0 == logicalIndex)
{
int iYOffset = m_pCheckBox->height() < rect.height()
? (rect.height() - m_pCheckBox->height()) /2 : 0;
QRect rectCheckBox(rect.x() + 3, rect.y() + iYOffset,
m_pCheckBox->width(), m_pCheckBox->height());
m_pCheckBox->setGeometry(rectCheckBox);
}
QHeaderView::paintSection(painter, rect, logicalIndex);
}
header()->setStyleSheet("\
QHeaderView::section {\
background-color:#f2f2f2;\
padding-left: 1px;\
border-left: 0;\
border-right: 0;\
border-top: 1px solid #cdd4df;\
border-bottom: 0;\
height: 25px;}\
QHeaderView::section:first{\
padding: 0px 0px 0px 22px;}\
QHeaderView::up-arrow{\
subcontrol-origin: padding;\
subcontrol-position: right;\
width: 15px; padding-right: 20px;}\
QHeaderView::down-arrow{\
subcontrol-origin: padding;\
subcontrol-position: right;\
width: 15px; padding-right: 20px;\
}");
- QHeaderView 禁用某些列排序和添加QCheckBox控件
- QTreeWidget项中添加控件(QCheckBox)和获取控件(QCheckBox)
- 如何在QTableWidget表头(列头)添加QCheckBox控件
- QListWidget添加QCheckBox控件
- QHeaderView添加右键菜单
- Qt之QHeaderView排序
- QTableView,QHeaderView 设置列宽
- 启用和禁用控件
- QHeaderView的visualIndex和logicalIndex
- Qt之QHeaderView添加复选框
- Qt QHeaderView 表头添加复选框
- QHeaderView 自带comboBox 等控件
- Windows 窗体 DataGrid 控件添加表和列
- Qt之QHeaderView自定义排序(QSortFilterProxyModel)
- QCheckBox
- 通过onkeypress和onkeydown事件禁用键盘中某些键
- 通过onkeypress和onkeydown事件禁用键盘中某些键
- MFC 启用和禁用控件
- 你因挣钱而伟大
- CocoaPods Guide
- 读HTML5应用与开发实践【二】【验证表单】
- 为solr添加中文分词器
- 电脑问题处理:关闭windows7 特效以减少内存占用
- QHeaderView 禁用某些列排序和添加QCheckBox控件
- 设计模式 笔记 命令模式 Command
- Weblogic在安装成功之后,本机可以访问,其他机器不可以访问的解决方案
- Ubuntu常用操作
- 编写C#程序 1-23
- 第八周 项目2-Time类中的运算符
- php正则表达式简明介绍
- JAVA中使用JSON进行数据传递
- ubuntu 配置Telnet服务