我正在嘗試重新實現(xiàn)QCheckBox的hitButton方法,以便只有實際的復選框(即不是標簽)是可點擊的。我不精通 C++,但查看QCheckBox的源代碼,我嘗試在 python 中重新實現(xiàn)現(xiàn)有代碼,看看我是否可以讓它按照我想要的方式工作。我的想法是我只需要更改SE_CheckBoxClickRect為SE_CheckBoxIndicator. 下面的內容似乎只在復選標記框的一個很小的區(qū)域內有效,在其他任何地方都沒有:class ClickCheckBox(QCheckBox): """subclass to reimplement hitButton""" def __init__(self, *args): super(ClickCheckBox, self).__init__(*args) def hitButton(self, QPoint): style = QStyle.SE_CheckBoxClickRect opt = QStyleOptionButton() return QApplication.style().subElementRect(style, opt, self).contains(QPoint)我怎樣才能使這項工作?
添加回答
舉報
0/150
提交
取消