PyQt:更改 QTableView 中复选框的对齐方式
我有一个带有复选框的 QTableView,但该复选框左对齐,我需要将其居中对齐。我尝试了这个,但是我的“检查”功能有问题:
def drawCheck(self, painter, option, rect, state):
textMargin = QtGui.QApplication.style().pixelMetric(QtGui.QStyle.PM_FocusFrameHMargin) + 1
checkRect = QtGui.QStyle.alignedRect(option.direction, QtCore.Qt.AlignCenter,
check(option, option.rect, QtCore.Qt.Checked).size(),
QtCore.QRect(option.rect.x() + textMargin, option.rect.y(),
option.rect.width() - (textMargin * 2), option.rect.height()))
QtGui.QItemDelegate.drawCheck(self, painter, checkRect, state)
什么是“检查”功能?如何在 PyQt 中重新实现 C++ 示例?
I have a QTableView
with checkbox, but the checkbox is aligned left, and I need to align it center. I tried this, but I have a problem with the "check" function:
def drawCheck(self, painter, option, rect, state):
textMargin = QtGui.QApplication.style().pixelMetric(QtGui.QStyle.PM_FocusFrameHMargin) + 1
checkRect = QtGui.QStyle.alignedRect(option.direction, QtCore.Qt.AlignCenter,
check(option, option.rect, QtCore.Qt.Checked).size(),
QtCore.QRect(option.rect.x() + textMargin, option.rect.y(),
option.rect.width() - (textMargin * 2), option.rect.height()))
QtGui.QItemDelegate.drawCheck(self, painter, checkRect, state)
What is the "check" function? How can I reimplement the C++ example in PyQt?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您链接到的示例代码没有
check
函数 - 这可能是一个已修复的拼写错误吗?或者它可能是代码本身定义的函数,而不是 Qt 的一部分?The example code you link to doesn't have a
check
function - could it be a typo that has been fixed? Or maybe it's a function defined in the code itself and isn't part ofQt
?