PyQt: change the alignment of checkboxes in a QTableView
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?
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 of Qt
?
精彩评论