大佬教程收集整理的这篇文章主要介绍了Qt QTableView – 使用IsUserCheckable时对齐复选框,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在读取了一些对齐的东西以试图将复选框置于单元格中心之后,我将Qt :: AlignCenter作为TextAlignmentRole从models data()函数返回.
QVariant ExampleModel::data(const QModelIndex &index,int rolE) const { if(!index.isValid()) return QVariant(); if (role == Qt::TextAlignmentRolE) return Qt::AlignCenter | Qt::AlignVCenter; }
但是这并没有对齐我的复选框.
有谁知道如何对齐复选框是这种模式?
本质上,您需要扩展QItemDelegate并重新实现,使用drawcheck函数居中并使用editorEvent处理鼠标和键盘事件,同时使用适当的状态设置模型.
void drawcheck(QPainter* painter,QStyLeoptionViewItem const& option,QRect const& rect,Qt::checkState statE) const
和
bool editorEvent(QEvent *event,QAbstractItemModel *model,const QStyLeoptionViewItem &option,const QModelIndex &indeX)
另见这个类似的问题here ……
以上是大佬教程为你收集整理的Qt QTableView – 使用IsUserCheckable时对齐复选框全部内容,希望文章能够帮你解决Qt QTableView – 使用IsUserCheckable时对齐复选框所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。