猿问

为什么我重新实现的 QCheckBox.hitButton 仅适用于检查指标的一小部分?

我正在尝试重新实现QCheckBox的hitButton方法,以便只有实际的复选框(即不是标签)是可点击的。我不精通 C++,但查看QCheckBox的源代码,我尝试在 python 中重新实现现有代码,看看我是否可以让它按照我想要的方式工作。


我的想法是我只需要更改SE_CheckBoxClickRect为SE_CheckBoxIndicator. 下面的内容似乎只在复选标记框的一个很小的区域内有效,在其他任何地方都没有:


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)

我怎样才能使这项工作?


翻阅古今
浏览 107回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答